Hacker News new | ask | show | jobs
by bigstrat2003 11 days ago
I'm really confused by the unwrap_or_break example in this text. The article says it wouldn't be possible to do without a macro, but how is it not equivalent to

  for d: Option<i32> in data {
    let val: i32 = match d {
      Some(v) => v,
      None => break
    };
    // Other stuff
  }
As far as I can tell that would do the exact same thing as the macro example.
2 comments

It said you can't do it with a regular function, not that you couldn't do it any other way.
Said the inner block inside the for loop could not be a function, because break does not mean anything not inside a loop, but the macro, which seems like a function, injects it into the code which is inside a loop, which is valid