Skip to content

Commit

Permalink
Merge pull request #103 from tarcieri/add-ctoption-expect
Browse files Browse the repository at this point in the history
Add `CtOption::expect`
  • Loading branch information
isislovecruft authored Feb 7, 2023
2 parents 29bb99b + f8b1f59 commit b4326d0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,18 @@ impl<T> CtOption<T> {
}
}

/// 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]
Expand Down

0 comments on commit b4326d0

Please sign in to comment.