diff --git a/src/lib.rs b/src/lib.rs index 43d87ff..d921041 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -618,6 +618,18 @@ impl CtOption { } } + /// Returns the contained value, consuming the `self` value. + /// + /// # Panics + /// + /// Panics if the value is none with a custom panic message provided by + /// `msg`. + pub fn expect(self, msg: &str) -> T { + assert_eq!(self.is_some.unwrap_u8(), 1, "{}", msg); + + self.value + } + /// This returns the underlying value but panics if it /// is not `Some`. #[inline]