3 ms·
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, an
by kd5bjo 5y ago
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&edition=2018&gist=f466f888f95c2cf3ccbeffbc10f76b7d 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&edition=2018&gist=a9d565552c4a8b37b123c42101e91239 https://play.rust-lang.org/?version=stable&mode=debug&editio...