Last active
October 9, 2021 03:13
-
-
Save songzhi/8e9550ea23927482a837e35f40ebc13d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// | |
/// ## Examples | |
/// ``` | |
/// enum Foo { | |
/// Path(String), | |
/// Count(usize), | |
/// } | |
/// let foo = Foo::Path(1); | |
/// let f: Option<String> = try_match!(foo, Foo::Path(x)=> x); | |
/// ``` | |
macro_rules! try_match { | |
($expression:expr, $( $pattern:pat_param )|+ $( if $guard: expr )? => $out: expr) => { | |
match $expression { | |
$( $pattern )|+ $( if $guard )? => ::core::option::Option::Some($out), | |
_ => ::core::option::Option::None, | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment