Re:Things you can’t do in Rust (and what to do instead)
by kd5bjo on Sunday May 16, 2021 @02:27AM
(#27171652)
The problem here is that you’re trying to iterate over `v` and modify it at the same time. The usual fix is to first decide the changes that should be made, and then apply them after the loop:
https://play.rust-lang.org/?version=stable&mode=debug&editio...
Alternatively, you can loop over indices instead of values, which doesn’t require the loop to maintain a reference to `v` across iterations:
https://play.rust-lang.org/?version=stable&mode=debug&editio...