Skip to content

Commit be3a71a

Browse files
committed
Add option::unwrap_expect
1 parent 160ffb0 commit be3a71a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/libcore/option.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ pure fn unwrap<T>(-opt: option<T>) -> T {
120120
}
121121
}
122122

123+
pure fn unwrap_expect<T>(-opt: option<T>, reason: ~str) -> T {
124+
//! As unwrap, but with a specified failure message.
125+
if opt.is_none() { fail reason; }
126+
unwrap(opt)
127+
}
128+
123129
impl extensions<T> for option<T> {
124130
/**
125131
* Update an optional value by optionally running its content through a

0 commit comments

Comments
 (0)