borrow checker won't let me push to a Vec while iterating it
Rust 1.79 here. I'm walking a Vec<String> and trying to push new items onto the same vec inside the loop. Compiler says cannot borrow words as mutable more than once at a time and points at my for word in &words line. I get why borrowing is the issue, but I can't see how to restructure this without cloning the whole vec every pass. It's a small parser, nothing fancy. Tried an index loop with while but then I hit a different borrow error on words[i]. What's the idiomatic way here?
3 replies