diff options
| author | Chris Morgan <me@chrismorgan.info> | 2013-12-14 23:22:01 +1100 |
|---|---|---|
| committer | Chris Morgan <me@chrismorgan.info> | 2013-12-14 23:22:01 +1100 |
| commit | 529f91572870cffdd9f13ddae12bb1f4e03186ab (patch) | |
| tree | e690f31fa381a416efa9d713230fb3f018917703 /src/libstd/result.rs | |
| parent | 844003683beb236616a069a233e66bfbe504427e (diff) | |
| download | rust-529f91572870cffdd9f13ddae12bb1f4e03186ab.tar.gz rust-529f91572870cffdd9f13ddae12bb1f4e03186ab.zip | |
Remove {As,Into,To}{Option,Either,Result} traits.
Expanded, that is: - `AsOption` - `IntoOption` - `ToOption` - `AsEither` - `IntoEither` - `ToEither` - `AsResult` - `IntoResult` - `ToResult` These were defined for each other but never *used* anywhere. They are all trivial and so removal will have negligible effect upon anyone. `Either` has fallen out of favour (and its implementation of these traits of dubious semantics), `Option<T>` → `Result<T, ()>` was never really useful and `Result<T, E>` → `Option<T>` should now be done with `Result.ok()` (mirrored with `Result.err()` for even more usefulness). In summary, there's really no point in any of these remaining.
Diffstat (limited to 'src/libstd/result.rs')
| -rw-r--r-- | src/libstd/result.rs | 132 |
1 files changed, 0 insertions, 132 deletions
diff --git a/src/libstd/result.rs b/src/libstd/result.rs index 690b4e06d49..79198d0314f 100644 --- a/src/libstd/result.rs +++ b/src/libstd/result.rs @@ -15,7 +15,6 @@ use cmp::Eq; use fmt; use iter::Iterator; use option::{None, Option, Some}; -use option::{ToOption, IntoOption, AsOption}; use str::OwnedStr; use to_str::ToStr; use vec::OwnedVector; @@ -205,81 +204,9 @@ impl<T, E> Result<T, E> { } ///////////////////////////////////////////////////////////////////////////// -// Constructor extension trait -///////////////////////////////////////////////////////////////////////////// - -/// A generic trait for converting a value to a `Result` -pub trait ToResult<T, E> { - /// Convert to the `result` type - fn to_result(&self) -> Result<T, E>; -} - -/// A generic trait for converting a value to a `Result` -pub trait IntoResult<T, E> { - /// Convert to the `result` type - fn into_result(self) -> Result<T, E>; -} - -/// A generic trait for converting a value to a `Result` -pub trait AsResult<T, E> { - /// Convert to the `result` type - fn as_result<'a>(&'a self) -> Result<&'a T, &'a E>; -} - -impl<T: Clone, E: Clone> ToResult<T, E> for Result<T, E> { - #[inline] - fn to_result(&self) -> Result<T, E> { self.clone() } -} - -impl<T, E> IntoResult<T, E> for Result<T, E> { - #[inline] - fn into_result(self) -> Result<T, E> { self } -} - -impl<T, E> AsResult<T, E> for Result<T, E> { - #[inline] - fn as_result<'a>(&'a self) -> Result<&'a T, &'a E> { - match *self { - Ok(ref t) => Ok(t), - Err(ref e) => Err(e), - } - } -} - -///////////////////////////////////////////////////////////////////////////// // Trait implementations ///////////////////////////////////////////////////////////////////////////// -impl<T: Clone, E> ToOption<T> for Result<T, E> { - #[inline] - fn to_option(&self) -> Option<T> { - match *self { - Ok(ref t) => Some(t.clone()), - Err(_) => None, - } - } -} - -impl<T, E> IntoOption<T> for Result<T, E> { - #[inline] - fn into_option(self) -> Option<T> { - match self { - Ok(t) => Some(t), - Err(_) => None, - } - } -} - -impl<T, E> AsOption<T> for Result<T, E> { - #[inline] - fn as_option<'a>(&'a self) -> Option<&'a T> { - match *self { - Ok(ref t) => Some(t), - Err(_) => None, - } - } -} - impl<T: fmt::Default, E: fmt::Default> fmt::Default for Result<T, E> { #[inline] fn fmt(s: &Result<T, E>, f: &mut fmt::Formatter) { @@ -364,8 +291,6 @@ mod tests { use super::*; use iter::range; - use option::{IntoOption, ToOption, AsOption}; - use option::{Some, None}; use vec::ImmutableVector; use to_str::ToStr; @@ -461,63 +386,6 @@ mod tests { } #[test] - pub fn test_to_option() { - let ok: Result<int, int> = Ok(100); - let err: Result<int, int> = Err(404); - - assert_eq!(ok.to_option(), Some(100)); - assert_eq!(err.to_option(), None); - } - - #[test] - pub fn test_into_option() { - let ok: Result<int, int> = Ok(100); - let err: Result<int, int> = Err(404); - - assert_eq!(ok.into_option(), Some(100)); - assert_eq!(err.into_option(), None); - } - - #[test] - pub fn test_as_option() { - let ok: Result<int, int> = Ok(100); - let err: Result<int, int> = Err(404); - - assert_eq!(ok.as_option().unwrap(), &100); - assert_eq!(err.as_option(), None); - } - - #[test] - pub fn test_to_result() { - let ok: Result<int, int> = Ok(100); - let err: Result<int, int> = Err(404); - - assert_eq!(ok.to_result(), Ok(100)); - assert_eq!(err.to_result(), Err(404)); - } - - #[test] - pub fn test_into_result() { - let ok: Result<int, int> = Ok(100); - let err: Result<int, int> = Err(404); - - assert_eq!(ok.into_result(), Ok(100)); - assert_eq!(err.into_result(), Err(404)); - } - - #[test] - pub fn test_as_result() { - let ok: Result<int, int> = Ok(100); - let err: Result<int, int> = Err(404); - - let x = 100; - assert_eq!(ok.as_result(), Ok(&x)); - - let x = 404; - assert_eq!(err.as_result(), Err(&x)); - } - - #[test] pub fn test_to_str() { let ok: Result<int, ~str> = Ok(100); let err: Result<int, ~str> = Err(~"Err"); |
