50.15.1Iterating over a vector’s items¶
Here is a version of the vector using string slices:
let fruits = vec!["banana", "strawberry", "orange"];Couldn't automatically determine type of variable `fruits`.
Please give it an explicit type.We loop on the vector’s elements using a vector’s reference:
for fruit in &fruits {
println!("{}", fruit.to_uppercase());
}The vector still contains its elements:
fruits.len()