[][src]Macro matches2::debug_assert_matches

macro_rules! debug_assert_matches {
    ($expression:expr, $($pattern:pat)|* $(if $ifguard:expr)?) => { ... };
    ($expression:expr, $($pattern:pat)|* $(if $ifguard:expr)?, $($msg:tt)+) => { ... };
}

Assert that an expression matches a refutable pattern using debug assertions.

Syntax: debug_assert_matches!( expression , pattern [ , error message ] )

If the pattern does not match while debug assertions are enabled, this macro panics with the given error message or a default one that contains the pattern in it. NB: The error message is passed through to panic! verbatim, so you can do debug_assert_matches!(..., "{}", 2).

Examples

#[macro_use]
extern crate matches2;

fn main() {
    let data = [1, 2, 3];
    debug_assert_matches!(data.get(1), Some(_), "This is not supposed to happen");
}