Add option::unwrap_expect

This commit is contained in:
Ben Blum 2012-07-24 15:46:40 -04:00
parent 160ffb0c2f
commit be3a71a1aa

View File

@ -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