diff options
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/option.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libcore/option.rs b/src/libcore/option.rs index b91a8cebded..45ccf657dbd 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -233,6 +233,20 @@ impl<T> Option<T> { // Getting to contained values ///////////////////////////////////////////////////////////////////////// + /// Unwraps an option, yielding the content of a `Some` + /// + /// # Failure + /// + /// Fails if the value is a `None` with a custom failure message provided by + /// `msg`. + #[inline] + pub fn expect(self, msg: &str) -> T { + match self { + Some(val) => val, + None => fail!(msg), + } + } + /// Moves a value out of an option type and returns it, consuming the `Option`. /// /// # Failure |
