Proposal
Problem statement
I need to convert an owned PathBuf into an owned String (if it is valid UTF-8). I would need to write path_buf.to_os_string().into_string(). Since a PathBuf is just a wrapper of OsString, I find having to type into_os_string unnecessary.
Internal discussions: https://internals.rust-lang.org/t/why-doesnt-the-into-string-method-be-available-directly-under-pathbuf-even-though-it-already-exists-in-osstring/19935
Motivating examples or use cases
Solution sketch
Just add the following method:
impl PathBuf {
pub fn into_string(self) -> Result<String, PathBuf> {
self.into_os_string().into_string().map_err(PathBuf::from)
}
}
Alternatives
There are other "direct" methods such as to_str or to_string_lossy but they all do unnecessary clone and allocation for owned types, so the only real alternative is into_os_string.
Links and related work
What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
- We think this problem seems worth solving, and the standard library might be the right place to solve it.
- We think that this probably doesn't belong in the standard library.
Second, if there's a concrete solution:
- We think this specific solution looks roughly right, approved, you or someone else should implement this. (Further review will still happen on the subsequent implementation PR.)
- We're not sure this is the right solution, and the alternatives or other materials don't give us enough information to be sure about that. Here are some questions we have that aren't answered, or rough ideas about alternatives we'd want to see discussed.
Proposal
Problem statement
I need to convert an owned
PathBufinto an ownedString(if it is valid UTF-8). I would need to writepath_buf.to_os_string().into_string(). Since aPathBufis just a wrapper ofOsString, I find having to typeinto_os_stringunnecessary.Internal discussions: https://internals.rust-lang.org/t/why-doesnt-the-into-string-method-be-available-directly-under-pathbuf-even-though-it-already-exists-in-osstring/19935
Motivating examples or use cases
Solution sketch
Just add the following method:
Alternatives
There are other "direct" methods such as
to_strorto_string_lossybut they all do unnecessary clone and allocation for owned types, so the only real alternative isinto_os_string.Links and related work
What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution: