Skip to content

Commit b4326d0

Browse files
Merge pull request #103 from tarcieri/add-ctoption-expect
Add `CtOption::expect`
2 parents 29bb99b + f8b1f59 commit b4326d0

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
@@ -618,6 +618,18 @@ impl<T> CtOption<T> {
618618
}
619619
}
620620

621+
/// Returns the contained value, consuming the `self` value.
622+
///
623+
/// # Panics
624+
///
625+
/// Panics if the value is none with a custom panic message provided by
626+
/// `msg`.
627+
pub fn expect(self, msg: &str) -> T {
628+
assert_eq!(self.is_some.unwrap_u8(), 1, "{}", msg);
629+
630+
self.value
631+
}
632+
621633
/// This returns the underlying value but panics if it
622634
/// is not `Some`.
623635
#[inline]

0 commit comments

Comments
 (0)