I was going through the Rust book from the official rust website and came across the following paragraph:
Note that we needed to make
v1_iter
mutable: calling the next method on an iterator changes internal state that the iterator uses to keep track of where it is in the sequence. In other words, this code consumes, or uses up, the iterator. Each call to next eats up an item from the iterator. We didn’t need to makev1_iter
mutable when we used a for loop because the loop took ownership ofv1_iter
and made it mutable behind the scenes.
If you notice the last line. It says the for loop makes a mutable variable immutable behind the scenes. If that's possible, then is it possible for us as a programmer to do the same?
Like I know it's not safe and we're not supposed to do that and stuff, but just wondering if that would be possible.