Skip to content

Commit

Permalink
libcore: add result::unwrap_err.
Browse files Browse the repository at this point in the history
  • Loading branch information
erickt committed Aug 31, 2012
1 parent 7649860 commit 5c6be13
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,14 @@ fn unwrap<T, U>(+res: Result<T, U>) -> T {
}
}

/// Unwraps a result, assuming it is an `err(U)`
fn unwrap_err<T, U>(+res: Result<T, U>) -> U {
match move res {
Err(move u) => u,
Ok(_) => fail ~"unwrap called on an ok result"
}
}

impl<T:Eq,U:Eq> Result<T,U> : Eq {
pure fn eq(&&other: Result<T,U>) -> bool {
match self {
Expand Down

0 comments on commit 5c6be13

Please sign in to comment.