macro_rules! try_match { ($in:expr, $(|)? $($p:pat)|+ $(if $guard:expr)? => $out:expr $(,)?) => { ... }; ($in:expr, $(|)? $($p:pat)|+ $(if $guard:expr)? $(,)?) => { ... }; (, $($pattern_and_rest:tt)*) => { ... }; }
Expand description
Try to match $in
against a given pattern $p
. Produces Ok($out)
if
successful; Err($in)
otherwise.
ⓘ
try_match!($( $in:expr )?, $p:pat_multi $( if $guard:expr )? $( => $out:expr )? $( , )?)
=> $out
can be left out, in which case it’s implied based on the number of
bound variables in $p
:
- If there are no bound variables, it is implied to be
()
. - If there is exactly one bound variable
var
, it is implied to bevar
. - If there are multiple bound variables
var1, var2, ...
, it is implied to beAnonymousType { var1, var2 }
.
AnonymousType
implements Clone
, Copy
, and Debug
.
$in
can be left out to produce a closure (partial
application).
See the crate-level documentation for examples.