diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/result.rs (renamed from src/libstd/result.rs) | 31 | ||||
| -rw-r--r-- | src/libstd/fmt/mod.rs | 9 | ||||
| -rw-r--r-- | src/libstd/hash/mod.rs | 13 |
3 files changed, 22 insertions, 31 deletions
diff --git a/src/libstd/result.rs b/src/libcore/result.rs index 922d2cf3d32..13f59d0875d 100644 --- a/src/libstd/result.rs +++ b/src/libcore/result.rs @@ -268,14 +268,13 @@ use clone::Clone; use cmp::Eq; -use std::fmt::Show; use iter::{Iterator, FromIterator}; use option::{None, Option, Some}; /// `Result` is a type that represents either success (`Ok`) or failure (`Err`). /// /// See the [`std::result`](index.html) module documentation for details. -#[deriving(Clone, Eq, Ord, TotalEq, TotalOrd, Show, Hash)] +#[deriving(Clone, Eq, Ord, TotalEq, TotalOrd)] #[must_use] pub enum Result<T, E> { /// Contains the success value @@ -516,34 +515,6 @@ impl<T, E> Result<T, E> { } } -impl<T, E: Show> Result<T, E> { - /// Unwraps a result, yielding the content of an `Ok`. - /// - /// Fails if the value is an `Err`. - #[inline] - pub fn unwrap(self) -> T { - match self { - Ok(t) => t, - Err(e) => - fail!("called `Result::unwrap()` on an `Err` value: {}", e) - } - } -} - -impl<T: Show, E> Result<T, E> { - /// Unwraps a result, yielding the content of an `Err`. - /// - /// Fails if the value is an `Ok`. - #[inline] - pub fn unwrap_err(self) -> E { - match self { - Ok(t) => - fail!("called `Result::unwrap_err()` on an `Ok` value: {}", t), - Err(e) => e - } - } -} - ///////////////////////////////////////////////////////////////////////////// // Free functions ///////////////////////////////////////////////////////////////////////////// diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs index 9f683e45678..8cfc0ae54c3 100644 --- a/src/libstd/fmt/mod.rs +++ b/src/libstd/fmt/mod.rs @@ -1291,6 +1291,15 @@ impl<T: Show> Show for Option<T> { } } +impl<T: Show, U: Show> Show for ::result::Result<T, U> { + fn fmt(&self, f: &mut Formatter) -> Result { + match *self { + Ok(ref t) => write!(f.buf, "Ok({})", *t), + Err(ref t) => write!(f.buf, "Err({})", *t), + } + } +} + impl<'a, T: Show> Show for &'a [T] { fn fmt(&self, f: &mut Formatter) -> Result { if f.flags & (1 << (parse::FlagAlternate as uint)) == 0 { diff --git a/src/libstd/hash/mod.rs b/src/libstd/hash/mod.rs index 010ddbaa942..c8207a4c37c 100644 --- a/src/libstd/hash/mod.rs +++ b/src/libstd/hash/mod.rs @@ -70,8 +70,9 @@ use iter::Iterator; use option::{Option, Some, None}; use owned::Box; use rc::Rc; -use str::{Str, StrSlice}; +use result::{Result, Ok, Err}; use slice::{Vector, ImmutableVector}; +use str::{Str, StrSlice}; use vec::Vec; /// Reexport the `sip::hash` function as our default hasher. @@ -292,6 +293,16 @@ impl<S: Writer> Hash<S> for TypeId { } } +impl<S: Writer, T: Hash<S>, U: Hash<S>> Hash<S> for Result<T, U> { + #[inline] + fn hash(&self, state: &mut S) { + match *self { + Ok(ref t) => { 1u.hash(state); t.hash(state); } + Err(ref t) => { 2u.hash(state); t.hash(state); } + } + } +} + ////////////////////////////////////////////////////////////////////////////// #[cfg(test)] |
