-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-UnicodeArea: UnicodeArea: UnicodeA-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`Area: `std::io`, `std::fs`, `std::net` and `std::path`A-strArea: str and StringArea: str and StringT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Description
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.
Metadata
Metadata
Assignees
Labels
A-UnicodeArea: UnicodeArea: UnicodeA-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`Area: `std::io`, `std::fs`, `std::net` and `std::path`A-strArea: str and StringArea: str and StringT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.