[][src]Macro cool_asserts::assert_matches

macro_rules! assert_matches {
    ($expression:expr, $pattern:pat $(if $guard:expr)? $(=> $block:expr)?, ) => { ... };
    ($expression:expr, $pattern:pat $(if $guard:expr)? $(=> $block:expr)? $(, $($fmt_arg:tt)+)?) => { ... };
}

Assert that the value of an expression matches a given pattern.

This assertion checks that the value of an expression matches a pattern. It panics if the expression does not match.

Optionally, provide a block with => { <block> }; the block will be run with the matched pattern if the match was successful. This allows running additional assertions on the matched pattern.

You can also add a trailing format message that will be included with the panic in the event of an assertion failure, just like with assert_eq!.

Example

use cool_asserts::{assert_matches, assert_panics};

assert_panics!{
    assert_matches!(Some(10), None),
    includes("value does not match pattern"),
}

assert_matches!(Some(10), Some(x) => {
    assert_eq!(x, 10);
})