about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-10-28 16:38:45 +0800
committerGitHub <noreply@github.com>2018-10-28 16:38:45 +0800
commitb9763de9b544ef5d01928eafdf5194850e94f340 (patch)
treebe519b56d1d631eb523eb3c2b6019f3f9ce74826 /src/libstd
parent1982f1887ad524951f24c12a6cc7bf05148aec14 (diff)
parenta0df4204c49975d3a5fb9c3a6562d49faf130b01 (diff)
downloadrust-b9763de9b544ef5d01928eafdf5194850e94f340.tar.gz
rust-b9763de9b544ef5d01928eafdf5194850e94f340.zip
Rollup merge of #55148 - SimonSapin:path-fromstr, r=oli-obk
Implement FromStr for PathBuf

Initially landed in https://github.com/rust-lang/rust/pull/48292 and reverted in https://github.com/rust-lang/rust/pull/50401. This time, use `std::string::ParseError` as suggested in https://github.com/rust-lang/rust/issues/44431#issuecomment-428112632
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/path.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs
index ca8be75fab5..a153456370c 100644
--- a/src/libstd/path.rs
+++ b/src/libstd/path.rs
@@ -87,6 +87,8 @@ use io;
 use iter::{self, FusedIterator};
 use ops::{self, Deref};
 use rc::Rc;
+use str::FromStr;
+use string::ParseError;
 use sync::Arc;
 
 use ffi::{OsStr, OsString};
@@ -1443,6 +1445,15 @@ impl From<String> for PathBuf {
     }
 }
 
+#[stable(feature = "path_from_str", since = "1.26.0")]
+impl FromStr for PathBuf {
+    type Err = ParseError;
+
+    fn from_str(s: &str) -> Result<Self, Self::Err> {
+        Ok(PathBuf::from(s))
+    }
+}
+
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<P: AsRef<Path>> iter::FromIterator<P> for PathBuf {
     fn from_iter<I: IntoIterator<Item = P>>(iter: I) -> PathBuf {