-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add OsStr::from_bytes() #26730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add OsStr::from_bytes() #26730
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
@@ -43,9 +42,6 @@ impl OsStringExt for OsString { | |||
/// Unix-specific extensions to `OsStr`. | |||
#[stable(feature = "rust1", since = "1.0.0")] | |||
pub trait OsStrExt { | |||
#[stable(feature = "rust1", since = "1.0.0")] | |||
fn from_bytes(slice: &[u8]) -> &Self; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is currently a stable method, so it can't be removed.
I like the idea of this, but I'm worried about this breaking code in practice. |
Sure, that's certainly much more compatible. Though we have to choose between symmetry with OsString (which has from_bytes()) and compatibility (keeping the current OsStrExt). I can do the rename if you want. |
We cannot compromise on compatibility, so while it's unfortunate that the symmetry is lost here we don't have any other recourse. |
Understood, that is very clear. |
Perhaps |
It seems to me that the best approaches are
|
Should be from_bytes(), since that the name of the method in OsString; however this is already used in OsStrExt on Unix. Thus from_bytes_slice(), which makes it clear why the name is different (this one operates on slices without copying).
I think that the current strategy taken is probably the best course of action, but I'd recommend the name |
This makes it possible to rename OsString::from_bytes() as well, since it is currently unstable (feature(convert)).
Sure thing! |
Looks good to me, thanks @remram44! Tagging with libs/needs-decision so this comes up in triage. |
Ok we talked about this in the triage meeting for libs this week, and we reached two conclusions:
Unfortunately there weren't any new insights about what the method should be called, but it was suggested that it should emphasize perhaps the parsing aspect for some platforms (e.g. |
|
Closing due to inactivity, but feel free to reopen with the a renaming! |
I did the rename, you can reopen. Not sure if the old |
Oh weird it looks like github doesn't allow me to reopen after a force push of the branch... Could you make a new PR? |
OsString::from_bytes()
turnsVec<u8>
intoOsString
. This adds the same thing, from&[u8]
to&OsStr
:Problem is that
OsStrExt
has a conflictingfrom_bytes()
(that always succeeds; unix-only). This PR removes it, which might need an RFC (it was Rust 1.0.0).OsStrExt
then only has an always-succeedingas_bytes()
, which could also be replaced byto_bytes().unwrap()
without loss of functionality.