Skip to content

Commit f12d5aa

Browse files
authored
Rollup merge of rust-lang#48292 - topecongiro:from_str-for-path-and-pathbuf, r=alexcrichton
Implement FromStr for PathBuf Closes rust-lang#44431.
2 parents c90f682 + 05a9acc commit f12d5aa

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/libstd/path.rs

+27
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ use io;
8787
use iter::{self, FusedIterator};
8888
use ops::{self, Deref};
8989
use rc::Rc;
90+
use str::FromStr;
9091
use sync::Arc;
9192

9293
use ffi::{OsStr, OsString};
@@ -1441,6 +1442,32 @@ impl From<String> for PathBuf {
14411442
}
14421443
}
14431444

1445+
/// Error returned from [`PathBuf::from_str`][`from_str`].
1446+
///
1447+
/// Note that parsing a path will never fail. This error is just a placeholder
1448+
/// for implementing `FromStr` for `PathBuf`.
1449+
///
1450+
/// [`from_str`]: struct.PathBuf.html#method.from_str
1451+
#[derive(Debug, Clone, PartialEq, Eq)]
1452+
#[stable(feature = "path_from_str", since = "1.26.0")]
1453+
pub enum ParsePathError {}
1454+
1455+
#[stable(feature = "path_from_str", since = "1.26.0")]
1456+
impl fmt::Display for ParsePathError {
1457+
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
1458+
match *self {}
1459+
}
1460+
}
1461+
1462+
#[stable(feature = "path_from_str", since = "1.26.0")]
1463+
impl FromStr for PathBuf {
1464+
type Err = ParsePathError;
1465+
1466+
fn from_str(s: &str) -> Result<Self, Self::Err> {
1467+
Ok(PathBuf::from(s))
1468+
}
1469+
}
1470+
14441471
#[stable(feature = "rust1", since = "1.0.0")]
14451472
impl<P: AsRef<Path>> iter::FromIterator<P> for PathBuf {
14461473
fn from_iter<I: IntoIterator<Item = P>>(iter: I) -> PathBuf {

0 commit comments

Comments
 (0)