Macro qed::const_assert_matches

source ·
macro_rules! const_assert_matches {
    ($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => { ... };
}
Expand description

Asserts that an expression matches any of the given patterns at compile time.

Like in a match expression, the pattern can be optionally followed by if and a guard expression that has access to names bound by the pattern.

See also const_assert!.

§Examples

qed::const_assert_matches!(NonZeroU8::new(0), None);
qed::const_assert_matches!(NonZeroU8::new(29), Some(_));
qed::const_assert_matches!(NonZeroU8::new(42), Some(nz) if nz.get() == 42);

Assertion failures will result in a compile error:

qed::const_assert_matches!(b"maybe c string".last(), Some(&0));