Skip to content

Commit a156534

Browse files
committed
core: Inherit the result module
The unwrap()/unwrap_err() methods are temporarily removed, and will be added back in the next commit.
1 parent f12b517 commit a156534

File tree

3 files changed

+22
-31
lines changed

3 files changed

+22
-31
lines changed

src/libstd/result.rs renamed to src/libcore/result.rs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,13 @@
268268
269269
use clone::Clone;
270270
use cmp::Eq;
271-
use std::fmt::Show;
272271
use iter::{Iterator, FromIterator};
273272
use option::{None, Option, Some};
274273

275274
/// `Result` is a type that represents either success (`Ok`) or failure (`Err`).
276275
///
277276
/// See the [`std::result`](index.html) module documentation for details.
278-
#[deriving(Clone, Eq, Ord, TotalEq, TotalOrd, Show, Hash)]
277+
#[deriving(Clone, Eq, Ord, TotalEq, TotalOrd)]
279278
#[must_use]
280279
pub enum Result<T, E> {
281280
/// Contains the success value
@@ -516,34 +515,6 @@ impl<T, E> Result<T, E> {
516515
}
517516
}
518517

519-
impl<T, E: Show> Result<T, E> {
520-
/// Unwraps a result, yielding the content of an `Ok`.
521-
///
522-
/// Fails if the value is an `Err`.
523-
#[inline]
524-
pub fn unwrap(self) -> T {
525-
match self {
526-
Ok(t) => t,
527-
Err(e) =>
528-
fail!("called `Result::unwrap()` on an `Err` value: {}", e)
529-
}
530-
}
531-
}
532-
533-
impl<T: Show, E> Result<T, E> {
534-
/// Unwraps a result, yielding the content of an `Err`.
535-
///
536-
/// Fails if the value is an `Ok`.
537-
#[inline]
538-
pub fn unwrap_err(self) -> E {
539-
match self {
540-
Ok(t) =>
541-
fail!("called `Result::unwrap_err()` on an `Ok` value: {}", t),
542-
Err(e) => e
543-
}
544-
}
545-
}
546-
547518
/////////////////////////////////////////////////////////////////////////////
548519
// Free functions
549520
/////////////////////////////////////////////////////////////////////////////

src/libstd/fmt/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,15 @@ impl<T: Show> Show for Option<T> {
12911291
}
12921292
}
12931293

1294+
impl<T: Show, U: Show> Show for ::result::Result<T, U> {
1295+
fn fmt(&self, f: &mut Formatter) -> Result {
1296+
match *self {
1297+
Ok(ref t) => write!(f.buf, "Ok({})", *t),
1298+
Err(ref t) => write!(f.buf, "Err({})", *t),
1299+
}
1300+
}
1301+
}
1302+
12941303
impl<'a, T: Show> Show for &'a [T] {
12951304
fn fmt(&self, f: &mut Formatter) -> Result {
12961305
if f.flags & (1 << (parse::FlagAlternate as uint)) == 0 {

src/libstd/hash/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ use iter::Iterator;
7070
use option::{Option, Some, None};
7171
use owned::Box;
7272
use rc::Rc;
73-
use str::{Str, StrSlice};
73+
use result::{Result, Ok, Err};
7474
use slice::{Vector, ImmutableVector};
75+
use str::{Str, StrSlice};
7576
use vec::Vec;
7677

7778
/// Reexport the `sip::hash` function as our default hasher.
@@ -292,6 +293,16 @@ impl<S: Writer> Hash<S> for TypeId {
292293
}
293294
}
294295

296+
impl<S: Writer, T: Hash<S>, U: Hash<S>> Hash<S> for Result<T, U> {
297+
#[inline]
298+
fn hash(&self, state: &mut S) {
299+
match *self {
300+
Ok(ref t) => { 1u.hash(state); t.hash(state); }
301+
Err(ref t) => { 2u.hash(state); t.hash(state); }
302+
}
303+
}
304+
}
305+
295306
//////////////////////////////////////////////////////////////////////////////
296307

297308
#[cfg(test)]

0 commit comments

Comments
 (0)