macro_rules! match_opt {
($expression:expr, $( $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)? => $output:expr ),* ) => { ... };
}
Expand description
Returns Some(output)
in case the given expression matches one of the given patterns
of the form pattern => output
, and None otherwise.
Like in a match
expression, the pattern can be optionally followed by if
and a guard expression that has access to names bound by the pattern. There can be several patterns.
ยงExamples
use match_opt::match_opt;
let foo = 'f';
let some_true = match_opt!(foo, 'A'..='Z' | 'a'..='z' => true);
let bar = Some(4);
let some_42 = match_opt!(bar, Some(x) if x > 2 => 42);