[][src]Macro try_match::try_match

macro_rules! try_match {
    ($p:pat = $in:expr => $out:expr) => { ... };
    ($p:pat = $($in:tt)*) => { ... };

Try to match $in against a given pattern $p. Produces Ok($out) if successful; Err($in) otherwise.

=> $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 variables var, it is implied to be var.
  • If there are multiple bound variables var1, var2, ..., it is implied to be AnonymousType { var1, var2 }.

AnonymousType derives Clone and Copy, and Debug if std feature is enabled.

See the crate-level documentation for examples.