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 the TryFrom 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 accept impl TryInto<&str>:
fn maybe_print<'a>(arg: impl TryInto<&'a str>) {
if let Ok(converted) = arg.try_into() {
println!("{converted}");
}
}
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.
Proposal
Problem statement
Currently it is impossible through use of the standard conversion traits to convert from an
&OsStrto a&str.Motivation, use-cases
Adding an implementation of
TryFrom<&OsStr>for&strmakes this conversion more discoverable to users who are already familiar with theTryFromtrait. They may even expect such an implementation to exist.Additionally it allows the use of
&OsStrin 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.