Skip to content

Commit cf08bce

Browse files
committed
Add an unwrap function.
1 parent e0d68d9 commit cf08bce

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ pub enum Result<T> {
5757
Err(Error),
5858
}
5959

60+
impl<T> Result<T> {
61+
/// Obtain the inner value, or panic - just like `core::Result::unwrap`.
62+
pub fn unwrap(self) -> T {
63+
match self {
64+
crate::Result::Ok(val) => val,
65+
crate::Result::Err(e) => {
66+
panic!("Unwrap called, got err {:?}", e);
67+
}
68+
}
69+
}
70+
}
71+
6072
/// All API functions which take/return optional values return this type. We
6173
/// don't use the `Option` type from the standard library because that isn't
6274
/// FFI safe and may change layout between compiler versions.

0 commit comments

Comments
 (0)