Skip to content

Commit

Permalink
Rollup merge of rust-lang#48292 - topecongiro:from_str-for-path-and-p…
Browse files Browse the repository at this point in the history
…athbuf, r=alexcrichton

Implement FromStr for PathBuf

Closes rust-lang#44431.
  • Loading branch information
Manishearth committed Mar 8, 2018
2 parents c90f682 + 05a9acc commit f12d5aa
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/libstd/path.rs
Expand Up @@ -87,6 +87,7 @@ use io;
use iter::{self, FusedIterator};
use ops::{self, Deref};
use rc::Rc;
use str::FromStr;
use sync::Arc;

use ffi::{OsStr, OsString};
Expand Down Expand Up @@ -1441,6 +1442,32 @@ impl From<String> for PathBuf {
}
}

/// Error returned from [`PathBuf::from_str`][`from_str`].
///
/// Note that parsing a path will never fail. This error is just a placeholder
/// for implementing `FromStr` for `PathBuf`.
///
/// [`from_str`]: struct.PathBuf.html#method.from_str
#[derive(Debug, Clone, PartialEq, Eq)]
#[stable(feature = "path_from_str", since = "1.26.0")]
pub enum ParsePathError {}

#[stable(feature = "path_from_str", since = "1.26.0")]
impl fmt::Display for ParsePathError {
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
match *self {}
}
}

#[stable(feature = "path_from_str", since = "1.26.0")]
impl FromStr for PathBuf {
type Err = ParsePathError;

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 {
Expand Down

0 comments on commit f12d5aa

Please sign in to comment.