Use for
loop on a rust array works correctly:
fn main() {
let v = [1, 2, 3, 4, 5];
for _ in v.into_iter() {}
for _ in v.into_iter() {}
}
But substituting a vec doesn't compile:
fn main() {
let v = vec![1, 2, 3, 4, 5];
for _ in v.into_iter() {}
for _ in v.into_iter() {}
}
The error:
use of moved value: `v`
I understand why this program does not work with vec. But why does it work with array? I was expecting a similar error in the array example, but it gives no error.