Skip to content

Commit

Permalink
Add option::unwrap_expect
Browse files Browse the repository at this point in the history
  • Loading branch information
bblum committed Jul 24, 2012
1 parent 160ffb0 commit be3a71a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ pure fn unwrap<T>(-opt: option<T>) -> T {
}
}

pure fn unwrap_expect<T>(-opt: option<T>, reason: ~str) -> T {
//! As unwrap, but with a specified failure message.
if opt.is_none() { fail reason; }
unwrap(opt)
}

impl extensions<T> for option<T> {
/**
* Update an optional value by optionally running its content through a
Expand Down

0 comments on commit be3a71a

Please sign in to comment.