Skip to content

Commit a0df420

Browse files
committed
Implement FromStr for PathBuf
Initially landed in #48292 and reverted in #50401. This time, use `std::string::ParseError` as suggested in #44431 (comment)
1 parent cbbd70d commit a0df420

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/libstd/path.rs

+11
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ use io;
8787
use iter::{self, FusedIterator};
8888
use ops::{self, Deref};
8989
use rc::Rc;
90+
use str::FromStr;
91+
use string::ParseError;
9092
use sync::Arc;
9193

9294
use ffi::{OsStr, OsString};
@@ -1443,6 +1445,15 @@ impl From<String> for PathBuf {
14431445
}
14441446
}
14451447

1448+
#[stable(feature = "path_from_str", since = "1.26.0")]
1449+
impl FromStr for PathBuf {
1450+
type Err = ParseError;
1451+
1452+
fn from_str(s: &str) -> Result<Self, Self::Err> {
1453+
Ok(PathBuf::from(s))
1454+
}
1455+
}
1456+
14461457
#[stable(feature = "rust1", since = "1.0.0")]
14471458
impl<P: AsRef<Path>> iter::FromIterator<P> for PathBuf {
14481459
fn from_iter<I: IntoIterator<Item = P>>(iter: I) -> PathBuf {

0 commit comments

Comments
 (0)