mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
Add option::unwrap_expect
This commit is contained in:
@@ -120,6 +120,12 @@ enum option<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
|
||||
|
||||
Reference in New Issue
Block a user