logoalt Hacker News

brcmthrowawaytoday at 12:56 AM1 replyview on HN

How does Rust avoid this?


Replies

trucks-refinishtoday at 1:11 AM

In rust you cannot mutate anything that is being read basically. The borrow checker enforces this.

So an iterator takes an immutable reference to the vector and mutation requires a mut ref, and you can't have both at the same time.