#[macro_export]
macro_rules! assert_matches {
($expression:expr, $( $pattern:pat )|+) => {
match $expression {
$( $pattern )|+ => {},
other => {
panic!(r#"assertion failed, expression does not match any of the given variants.
expression: {:?}
variants: {}"#, other, stringify!($($pattern) |+));
}
}
};
($expression:expr, $( $pattern:pat )|+ if $guard: expr) => {
match $expression {
$( $pattern )|+ if $guard => {},
other => {
panic!(r#"assertion failed, expression does not match any of the given variants.
expression: {:?}
variants: {}"#, other, stringify!($($pattern) |+ if $guard));
}
}
};
($expression:expr, $( $pattern:pat )|+, $($arg:tt)+) => {
match $expression {
$( $pattern )|+ => {},
other => {
panic!(r#"assertion failed, expression does not match any of the given variants.
expression: {:?}
variants: {}: {}"#, other, stringify!($($pattern) |+), format_args!($($arg)+));
}
}
};
($expression:expr, $( $pattern:pat )|+ if $guard: expr, $($arg:tt)+) => {
match $expression {
$( $pattern )|+ if $guard => {},
other => {
panic!(r#"assertion failed, expression does not match any of the given variants.
expression: {:?}
variants: {}: {}"#, other, stringify!($($pattern) |+ if $guard), format_args!($($arg)+));
}
}
};
}
#[macro_export]
macro_rules! debug_assert_matches {
($($arg:tt)*) => (if cfg!(debug_assertions) { $crate::assert_matches!($($arg)*); })
}