Hi,
I'm struggling to understand why and how this code works:
fn iter1() {
let samples = vec![1, 2, 3];
let mut iter = samples.into_iter();
for i in 0..3 {
let n = (&mut iter).count();
println!("Iterator has {} items", n)
}
}
count
method takes ownership of the iterator. So without &mut
it'll give obvious "use of moved value" error. But with &mut
it works. However if it would just dereference, it should give error "cannot move out of borrowed content"? What exactly is happening in background?