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
{{ message }}
Repository navigation
String::from_utf16_lossy signature differs from from_utf8_lossy #32874
String::from_utf8_lossy returns a Cow<'a, str> while String::from_utf16_lossy returns simply String. It would be useful for their signature to both match. String::from_utf16_lossy should return Cow<'a, str> as well, though this is obviously a breaking, but easily solved, change.
Yeah unfortunately these signatures can't change (as they're stable), but they're both intended to return "string-like types" in whichever way is most suitable, but perhaps the docs can be bolstered up to emphasize that!
Relabeling as a docs issue since we can't change these APIs. However, I'm not entirely sure what needs to be changed here. Specifically, we should mention that conversion from UTF-16 can never be done without allocating, so we don't return a Cow. I'm personally not sure this is a good idea, but I can see the benefits, since it explains the API inconsistency.
Activity
bluss commentedon Apr 11, 2016
The conversion from utf-16 can never result in a &str, since the representation of the data changes from using u16 units to u8.
nagisa commentedon Apr 11, 2016
Moreover you can trivially convert an owned datatype to Cow with
into:alexcrichton commentedon Apr 11, 2016
Yeah unfortunately these signatures can't change (as they're stable), but they're both intended to return "string-like types" in whichever way is most suitable, but perhaps the docs can be bolstered up to emphasize that!
Mark-Simulacrum commentedon Jun 16, 2017
Relabeling as a docs issue since we can't change these APIs. However, I'm not entirely sure what needs to be changed here. Specifically, we should mention that conversion from UTF-16 can never be done without allocating, so we don't return a Cow. I'm personally not sure this is a good idea, but I can see the benefits, since it explains the API inconsistency.
frewsxcv commentedon Sep 14, 2017
Opened a PR for this: #44572