Hacker News new | ask | show | jobs
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.
1 comments

Bleah, Rust's println makes my eyes bleed.. What's didn't you do 'println!("x value={x}");'?? Yes, I know you can use 'println!("x value={u}",u=x);', it still isn't a good syntax IMHO.