|
|
|
|
|
by andolanra
4405 days ago
|
|
You could always write this yourself with a macro: macro_rules! if_let {
($p:pat = $init:expr in $e:expr) => {
{ match $init { $p => $e,_ => {}, } }
}
}
fn main() {
let tup = (2, 3);
if_let!{(2, x) = tup in println!("x={}", x)}; // prints x=3
if_let!{(5, x) = tup in println!("x={}", x)}; // doesn't print
}
It's slightly more heavyweight, but still not too bad. |
|