Skip to content

Commit 35d9901

Browse files
SimonSapinischeinkman
authored andcommitted
Implement FromStr for PathBuf
Initially landed in rust-lang#48292 and reverted in rust-lang#50401. This time, use `std::string::ParseError` as suggested in rust-lang#44431 (comment)
1 parent d7464df commit 35d9901

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/libstd/path.rs

Lines changed: 11 additions & 0 deletions
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};
@@ -1446,6 +1448,15 @@ impl From<String> for PathBuf {
14461448
}
14471449
}
14481450

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

0 commit comments

Comments
 (0)