claims

Macro assert_none

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

Asserts that the expression is None.

§Uses

Assertions are always checked in both debug and release builds, and cannot be disabled. See debug_assert_none! 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: Option<i32> = None;

assert_none!(maybe);

// With a custom message
assert_none!(maybe, "Yep, there is nothing in here");
assert_none!(maybe, "we asserting that there are no droids we are looking for at {:?}", maybe);

A Some(_) variant will panic:

let maybe = Some(42i32);

assert_none!(maybe);  // Will panic