about summary refs log tree commit diff
path: root/src/libstd/path
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-01-30 12:03:20 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-01-30 12:03:20 -0800
commitac1a03d7422ba52749e4e513a46c8d2129c2c817 (patch)
treecefa26a551d7703c5f8534cc6661432348c93e06 /src/libstd/path
parent0ba812fbf00e3026b29282e1a72d58ea7959833e (diff)
parent0cdde6e5e015ee6f6d9381ab624a312af7c9b069 (diff)
downloadrust-ac1a03d7422ba52749e4e513a46c8d2129c2c817.tar.gz
rust-ac1a03d7422ba52749e4e513a46c8d2129c2c817.zip
rollup merge of #21718: alexcrichton/stabilize-from-str
This commits adds an associated type to the `FromStr` trait representing an
error payload for parses which do not succeed. The previous return value,
`Option<Self>` did not allow for this form of payload. After the associated type
was added, the following attributes were applied:

* `FromStr` is now stable
* `FromStr::Err` is now stable
* `FromStr::from_str` is now stable
* `StrExt::parse` is now stable
* `FromStr for bool` is now stable
* `FromStr for $float` is now stable
* `FromStr for $integral` is now stable
* Errors returned from stable `FromStr` implementations are stable
* Errors implement `Display` and `Error` (both impl blocks being `#[stable]`)

Closes #15138
Diffstat (limited to 'src/libstd/path')
-rw-r--r--src/libstd/path/posix.rs13
-rw-r--r--src/libstd/path/windows.rs13
2 files changed, 22 insertions, 4 deletions
diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs
index 588f724134e..72c41f2399e 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(Show, 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 98e0320cd14..e04f697b2a4 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(Show, Clone, PartialEq, Copy)]
+pub struct ParsePathError;
+
 impl<S: hash::Writer + hash::Hasher> hash::Hash<S> for Path {
     #[cfg(not(test))]
     #[inline]