-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Implement TryFrom<&OsStr>
for &str
#99031
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
Comments
@aticu can you give a more concrete example of a situation where you'd use this? |
I don't remember the exact details (and I currently don't have access to the code), but as far as I remember I was trying to do some checks on the contents of an So for my specific situation this |
I think it's reasonable for this conversion to exist -- it's a fallible conversion that exists as an inherent method, it seems inconsistent if we're going to decide that it shouldn't exist via our trait for fallible conversions. Or am I missing something that makes this case less straightforward than it seems? (perhaps we'd change things in a world where we guarantee the encoding?) |
I agree and I don't think you're missing anything, I just wanted the concrete use case because I think its often very useful context. I think all of the complexity for this proposal is going to be in figuring out the proper Error type. Also, I just realized this change isn't unstable, it's insta-stable, so it will need an FCP not an ACP. |
I'm retagging this since it's an insta-stable change that needs an FCP. Along those lines, I'm not sure if rfcbot is setup to work on this repo, but there's an easy way to find out. @rfcbot merge |
Team member @yaahc has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 psst @yaahc, I wasn't able to add the |
Is this ever able to succeed on Windows? An OsStr there is not utf8, and this is known at compile time. Relegating it to a runtime failure seems a poor result. |
On Windows we use WTF-8 for |
Windows itself uses "WTF-16" (aka UTF-16 with unpaired surrogates) but the standard library translate from/to WTF-8 at the API boundary. We also guarantee that an |
Ah that makes sense. I had no idea an OsStr(ing) needed a copy for win32 (except maybe for Win11) |
What's the status here? Shouldn't the FCP have already ended? |
looks like rfcbot had issues with the issue transfer from the libs-team repo. |
The final comment period, with a disposition to merge, as per the #99031 (comment), is now complete. As This will be merged soon. hopefully this is an accurate enough recreation of rfcbot's job to not mess up any other processes, 😅 |
…=Amanieu Implement `TryFrom<&OsStr>` for `&str` Recently when trying to work with `&OsStr` I was surprised to find this `impl` missing. Since the `to_str` method already existed the actual implementation is fairly non-controversial, except for maybe the choice of the error type. I chose an opaque error here instead of something like `std::str::Utf8Error`, since that would already make a number of assumption about the underlying implementation of `OsStr`. As this is a trait implementation, it is insta-stable, if I'm not mistaken? Either way this will need an FCP. I chose "1.64.0" as the version, since this is unlikely to land before the beta cut-off. `@rustbot` modify labels: +T-libs-api API Change Proposal: rust-lang#99031 (accepted)
Implement `TryFrom<&OsStr>` for `&str` Recently when trying to work with `&OsStr` I was surprised to find this `impl` missing. Since the `to_str` method already existed the actual implementation is fairly non-controversial, except for maybe the choice of the error type. I chose an opaque error here instead of something like `std::str::Utf8Error`, since that would already make a number of assumption about the underlying implementation of `OsStr`. As this is a trait implementation, it is insta-stable, if I'm not mistaken? Either way this will need an FCP. I chose "1.64.0" as the version, since this is unlikely to land before the beta cut-off. `@rustbot` modify labels: +T-libs-api API Change Proposal: rust-lang/rust#99031 (accepted)
Proposal
Problem statement
Currently it is impossible through use of the standard conversion traits to convert from an
&OsStr
to a&str
.Motivation, use-cases
Adding an implementation of
TryFrom<&OsStr>
for&str
makes this conversion more discoverable to users who are already familiar with theTryFrom
trait. They may even expect such an implementation to exist.Additionally it allows the use of
&OsStr
in more generic methods such as those that acceptimpl TryInto<&str>
:Solution sketches
Implement
TryFrom<&OsStr>
for&str
.Links and related work
Implementation PR: #98202
What happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.
The text was updated successfully, but these errors were encountered: