In Chapter 8 of the Rust Book they give they following example:
let v = vec![100, 32, 57];
for i in &v {
println!("{}", i);
}
I don't understand why &v
was used instead of v
.
If v
is immutable what is the purpose of using a reference instead of v
itself?