Created
August 16, 2019 10:36
-
-
Save rust-play/6f5080c5bcf27430d64770730181fd70 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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
macro_rules! iflet { | |
([$p:pat = $e:expr] $($rest:tt)*) => { | |
if let $p = $e { | |
iflet!($($rest)*); | |
} | |
}; | |
($b:block) => { | |
$b | |
}; | |
} | |
fn main() { | |
iflet!([Some(a) = foo_a()] [Some(b) = foo_b()] [Some(c) = foo_c()] { | |
println!("{} {} {}", a, b, c); | |
}); | |
} | |
fn foo_a() -> Option<u32> { | |
Some(0) | |
} | |
fn foo_b() -> Option<u32> { | |
Some(1) | |
} | |
fn foo_c() -> Option<u32> { | |
Some(2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment