Skip to content

Commit 05a9acc

Browse files
committed
Implement FromStr for PathBuf
1 parent 58a8e0c commit 05a9acc

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};
@@ -1397,6 +1398,32 @@ impl From<String> for PathBuf {
13971398
}
13981399
}
13991400

1401+
/// Error returned from [`PathBuf::from_str`][`from_str`].
1402+
///
1403+
/// Note that parsing a path will never fail. This error is just a placeholder
1404+
/// for implementing `FromStr` for `PathBuf`.
1405+
///
1406+
/// [`from_str`]: struct.PathBuf.html#method.from_str
1407+
#[derive(Debug, Clone, PartialEq, Eq)]
1408+
#[stable(feature = "path_from_str", since = "1.26.0")]
1409+
pub enum ParsePathError {}
1410+
1411+
#[stable(feature = "path_from_str", since = "1.26.0")]
1412+
impl fmt::Display for ParsePathError {
1413+
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
1414+
match *self {}
1415+
}
1416+
}
1417+
1418+
#[stable(feature = "path_from_str", since = "1.26.0")]
1419+
impl FromStr for PathBuf {
1420+
type Err = ParsePathError;
1421+
1422+
fn from_str(s: &str) -> Result<Self, Self::Err> {
1423+
Ok(PathBuf::from(s))
1424+
}
1425+
}
1426+
14001427
#[stable(feature = "rust1", since = "1.0.0")]
14011428
impl<P: AsRef<Path>> iter::FromIterator<P> for PathBuf {
14021429
fn from_iter<I: IntoIterator<Item = P>>(iter: I) -> PathBuf {

0 commit comments

Comments
 (0)