diff options
| author | bors <bors@rust-lang.org> | 2015-01-31 03:57:01 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-01-31 03:57:01 +0000 |
| commit | 474b324eda10440d6568ef872a7307d38e7de95b (patch) | |
| tree | 53fc5aaa615f1c6e5abd757e42a75b3d19ce3abb /src/libstd/path | |
| parent | 1d00c545ede609b9d43fdf9f252c15da5a66dac7 (diff) | |
| parent | e8fd9d3d0bf0f4974460337df29c0d3ceb514987 (diff) | |
| download | rust-474b324eda10440d6568ef872a7307d38e7de95b.tar.gz rust-474b324eda10440d6568ef872a7307d38e7de95b.zip | |
Auto merge of #21791 - alexcrichton:rollup, r=alexcrichton
Diffstat (limited to 'src/libstd/path')
| -rw-r--r-- | src/libstd/path/posix.rs | 13 | ||||
| -rw-r--r-- | src/libstd/path/windows.rs | 15 |
2 files changed, 23 insertions, 5 deletions
diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 588f724134e..6a0c8a93010 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -19,6 +19,7 @@ use iter::{AdditiveIterator, Extend}; use iter::{Iterator, IteratorExt, Map}; use marker::Sized; use option::Option::{self, Some, None}; +use result::Result::{self, Ok, Err}; use slice::{AsSlice, Split, SliceExt, SliceConcatExt}; use str::{self, FromStr, StrExt}; use vec::Vec; @@ -86,11 +87,19 @@ impl Ord for Path { } impl FromStr for Path { - fn from_str(s: &str) -> Option<Path> { - Path::new_opt(s) + type Err = ParsePathError; + fn from_str(s: &str) -> Result<Path, ParsePathError> { + match Path::new_opt(s) { + Some(p) => Ok(p), + None => Err(ParsePathError), + } } } +/// Valuelue indicating that a path could not be parsed from a string. +#[derive(Debug, Clone, PartialEq, Copy)] +pub struct ParsePathError; + impl<S: hash::Writer + hash::Hasher> hash::Hash<S> for Path { #[inline] fn hash(&self, state: &mut S) { diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 88db27013ac..b524b89ef9f 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -27,6 +27,7 @@ use mem; use option::Option::{self, Some, None}; #[cfg(stage0)] use ops::FullRange; +use result::Result::{self, Ok, Err}; use slice::{SliceExt, SliceConcatExt}; use str::{SplitTerminator, FromStr, StrExt}; use string::{String, ToString}; @@ -115,11 +116,19 @@ impl Ord for Path { } impl FromStr for Path { - fn from_str(s: &str) -> Option<Path> { - Path::new_opt(s) + type Err = ParsePathError; + fn from_str(s: &str) -> Result<Path, ParsePathError> { + match Path::new_opt(s) { + Some(p) => Ok(p), + None => Err(ParsePathError), + } } } +/// Value indicating that a path could not be parsed from a string. +#[derive(Debug, Clone, PartialEq, Copy)] +pub struct ParsePathError; + impl<S: hash::Writer + hash::Hasher> hash::Hash<S> for Path { #[cfg(not(test))] #[inline] @@ -557,7 +566,7 @@ impl GenericPath for Path { } (Some(a), Some(_)) => { comps.push(".."); - for _ in itb { + for _ in itb.by_ref() { comps.push(".."); } comps.push(a); |
