[][src]Macro assert2::let_assert

macro_rules! let_assert {
    ($($tokens:tt)*) => { ... };
}
This is supported on feature="let-assert" and proc_macro_hygiene only.

Assert that an expression matches a pattern.

This is very similar to assert!(let pattern = expression), except that this macro makes all placeholders available in the calling scope. This can be used to assert a pattern match, and then run more checks on the captured variables.

This macro is only available if if the let-assert feature of the assert2 crate is enabled, and it requires the proc_macro_hygiene rust feature to be enabled by the user of the macro.

For example:

#![feature(proc_macro_hygiene)]

let_assert!(Ok(foo) = Foo::try_new("bar"));
check!(foo.name() == "bar");

let_assert!(Err(Error::InvalidName(e)) = Foo::try_new("bogus name"));
check!(e.name() == "bogus name");
check!(e.to_string() == "invalid name: bogus name");