Macro guard::guard_unwrap
source · macro_rules! guard_unwrap { ($($input:tt)*) => { ... }; }
Expand description
Match a pattern to an expression, binding identifiers in the calling scope. Panic if the match fails.
Supported syntax:
- let
pattern
=rhs
Inputs:
rhs
: expression to match against the patternpattern
: pattern. Seeguard
for details on which patterns are accepted.
Note that pattern guards are not supported.
#[macro_use] extern crate guard;
guard_unwrap!(let Some(foo) = Some(42));
assert_eq!(foo, 42);
Here’s an example of a failing match that causes [guard_unwrap
] to panic.
ⓘ
#[macro_use] extern crate guard;
guard_unwrap!(let Option::None = Some(42));
Note that Option::None
is used instead of None
to work around the limitations
of accepted patterns. See guard
for details.
Also note that this macro is mostly provided for destructuring enums in tests. In production code it’s usually better to handle all variants of enums explicitly.