macro_rules! try_match { ($var:expr, $variant:path) => { ... }; }
Expand description
Attempts to get variant from the enum variable.
§Examples
#[derive(Debug, PartialEq)]
enum Foo {
Left(u16),
Right(&'static str),
}
assert_eq!(try_match!(Foo::Left(18), Foo::Left), Ok(18));
assert_eq!(
try_match!(Foo::Right("nope"), Foo::Left),
Err(Foo::Right("nope"))
);