Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created August 16, 2019 10:36
Show Gist options
  • Save rust-play/6f5080c5bcf27430d64770730181fd70 to your computer and use it in GitHub Desktop.
Save rust-play/6f5080c5bcf27430d64770730181fd70 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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