Macro mz_ore::assert_none

source ·
macro_rules! assert_none {
    ($val:expr, $($msg:tt)+) => { ... };
    ($val:expr) => { ... };
}
Available on crate feature test only.
Expand description

Asserts that the provided expression, that returns an Option, is None.

§Motivation

The standard pattern for asserting a value is None using the assert! macro is:

assert!(x.is_none());

The issue with this pattern is when the assertion fails it only prints false and not the value contained in the Some(_) variant which makes debugging difficult.

§Examples

§Basic Use

use mz_ore::assert_none;
assert_none!(Some(42));

§With extra message

use mz_ore::assert_none;
let other_val = 100;
assert_none!(Some(42), "ohh noo! x {other_val}");