spin_common/assert.rs
1//! Assertion macros.
2
3/// Asserts that the expression matches the pattern.
4///
5/// This is equivalent to `assert!(matches!(...))` except that it produces nicer
6/// errors.
7#[macro_export]
8macro_rules! assert_matches {
9 ($expr:expr, $pat:pat $(,)?) => {{
10 let val = $expr;
11 assert!(
12 matches!(val, $pat),
13 "expected {val:?} to match {}",
14 stringify!($pat),
15 )
16 }};
17}
18
19/// Asserts that the expression does not match the pattern.
20///
21/// This is equivalent to `assert!(!matches!(...))` except that it produces
22/// nicer errors.
23#[macro_export]
24macro_rules! assert_not_matches {
25 ($expr:expr, $pat:pat $(,)?) => {{
26 let val = $expr;
27 assert!(
28 !matches!(val, $pat),
29 "expected {val:?} to NOT match {}",
30 stringify!($pat),
31 )
32 }};
33}