4 ms·
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
by bigstrat2003 5mo 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.
- gwerbin 5mo agoIt said you can't do it with a regular function, not that you couldn't do it any other way.
- Sagi21805 5mo agoSaid 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