You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Warn against use of Cow<String> or Cow<Vec<u8>>, instead of Cow<str> or Cow<[u8]>.
[u8] is an unusual type, and it's not obvious that Cow<[u8]> can hold a Vec<u8>, so users can mistakenly use Cow<Vec<u8>> instead. However, Cow<Vec<u8>> wasn't meant to be used. It creates an extra level of indirection, and Cow::Borrowed is limited to holding a less-general &Vec instead of a slice. Both Cow<[u8]> and Cow<Vec<u8>> have the same size, so the other form doesn't even benefit from holding a thin pointer.
Same for CStr, OsStr, Path. From implementation perspective, I think it could warn when Cow<X> is used, and there exists Cow<Y, Owned = X>, and X != Y.
Advantage
It helps users discover the intended types for use in Cow, where the type argument is for a non-owned type, not the owned one.
Drawbacks
None?
Example
Cow<'_,Vec<u8>>
Could be written as:
Cow<'_,[u8]>
The text was updated successfully, but these errors were encountered:
What it does
Warn against use of
Cow<String>
orCow<Vec<u8>>
, instead ofCow<str>
orCow<[u8]>
.[u8]
is an unusual type, and it's not obvious thatCow<[u8]>
can hold aVec<u8>
, so users can mistakenly useCow<Vec<u8>>
instead. However,Cow<Vec<u8>>
wasn't meant to be used. It creates an extra level of indirection, andCow::Borrowed
is limited to holding a less-general&Vec
instead of a slice. BothCow<[u8]>
andCow<Vec<u8>>
have the same size, so the other form doesn't even benefit from holding a thin pointer.Same for
CStr
,OsStr
,Path
. From implementation perspective, I think it could warn whenCow<X>
is used, and there existsCow<Y, Owned = X>
, andX != Y
.Advantage
It helps users discover the intended types for use in
Cow
, where the type argument is for a non-owned type, not the owned one.Drawbacks
None?
Example
Could be written as:
The text was updated successfully, but these errors were encountered: