Iteration moves values
- If we remove the
&from the first iteration the code won’t compile any more as we have moved the values.
fn main() {
let animals = vec![
String::from("cat"),
String::from("dog"),
String::from("crab"),
];
for animal in &animals {
println!("{animal}");
}
println!();
for animal in animals {
println!("{animal}");
}
}
cat
dog
crab
cat
dog
crab