From d8e52c100241245489c08bfca2011d050ea4eb4e Mon Sep 17 00:00:00 2001 From: Jayson Reis Date: Sat, 9 Nov 2019 12:11:08 +0100 Subject: [PATCH] Implement FromStr for PathBuf This makes PathBuf compatible with std version as you can simply call let path: PathBuf = FromStr::from_str(s).unwrap() --- src/path/pathbuf.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/path/pathbuf.rs b/src/path/pathbuf.rs index c95103f..aae5de6 100644 --- a/src/path/pathbuf.rs +++ b/src/path/pathbuf.rs @@ -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 { + Ok(std::path::PathBuf::from(s).into()) + } +} + impl AsRef for PathBuf { fn as_ref(&self) -> &Path { Path::new(&self.inner)