Macro matches2::assert_matches [−][src]
macro_rules! assert_matches { ($expression:expr, $(|)* $pattern:pat $(|$pattern_extra:pat)* $(if $ifguard:expr)*) => { ... }; ($expression:expr, $(|)* $pattern:pat $(|$pattern_extra:pat)* $(if $ifguard:expr)*, $($msg:tt)+) => { ... }; }
Assert that an expression matches a refutable pattern.
Syntax: assert_matches!(
expression ,
pattern [, error message ])
If the pattern does not match, 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 assert_matches!(..., "{}", 2)
.
Examples
#[macro_use] extern crate matches2; fn main() { let data = [1, 2, 3]; assert_matches!(data.get(1), Some(_)); }