claims

Macro assert_some

Source
macro_rules! assert_some {
    ($cond:expr $(,)?) => { ... };
    ($cond:expr, $($arg:tt)+) => { ... };
}
Expand description

Asserts that the expression matches a Some(_) variant, returning the contained value.

§Uses

Assertions are always checked in both debug and release builds, and cannot be disabled. See debug_assert_some! for assertions that are not enabled in release builds by default.

§Custom messages

This macro has a second form, where a custom panic message can be provided with or without arguments for formatting. See std::fmt for syntax for this form.

§Examples

let maybe = Some(42);

assert_some!(maybe);

// With a custom message
assert_some!(maybe, "Found it at {:?}", maybe);

A None variant will panic:

let maybe = None;

assert_some!(maybe);  // Will panic