4 ms·
What the for loop actually expands to is much easier to read. [<label>] for <pat> in <iterator expression> { ... } let __iterator = &mut <iterator exp
by kzrdude 12y ago
What the for loop actually expands to is much easier to read.
[<label>] for <pat> in <iterator expression> { ... }
let __iterator = &mut <iterator expression>;
<label> loop {
match __iterator.next() {
None => break,
Some(<pat>) => { ... }
}
}
- sfvisser 12y agoMuch easier to read to who? Not to me at least. Code readability is subjective and depends on experience and familiarity.
- dbaupp 12y agoIt doesn't actually expand to that any more. You can see what it does expand to by running rustc --pretty expanded with a recent compiler: for pattern in iterator { body } becomes match &mut iterator { i => loop { match i.next() { None => break , Some(mut _value) => { let pattern = _value; { body } } } } }
- knz42 12y agoI did not know that for was actually expanded early in the compiler and that one could print out the expansion with --pretty expanded. Color me enlightened. I have incorporated this, thanks!