Implement FromStr for PathBuf

This makes PathBuf compatible with std version as you can simply call
let path: PathBuf = FromStr::from_str(s).unwrap()
This commit is contained in:
Jayson Reis 2019-11-09 12:11:08 +01:00
parent 037119c0c0
commit d8e52c1002
No known key found for this signature in database
GPG key ID: 32CAA472083D88E2

View file

@ -1,6 +1,7 @@
use std::ffi::{OsStr, OsString};
#[cfg(feature = "unstable")]
use std::pin::Pin;
use std::str::FromStr;
use crate::path::Path;
#[cfg(feature = "unstable")]
@ -228,6 +229,14 @@ impl From<&str> for PathBuf {
}
}
impl FromStr for PathBuf {
type Err = core::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(std::path::PathBuf::from(s).into())
}
}
impl AsRef<Path> for PathBuf {
fn as_ref(&self) -> &Path {
Path::new(&self.inner)