In this example program, we create an array of 10 vectors. Each vector is separate, and represents a separate region of memory.
fn main() {
// Specify an empty vector as a constant.
const EMPTY: Vec<i32> = vec![];
// Initialize the array.
let mut array = [EMPTY; 10];
// Loop over the array vectors and push 3 numbers to each one.
for array in array.iter_mut() {
array.push(1);
array.push(2);
array.push(3);
}
// Print the vector data in the array.
for array in array.iter() {
println!(
"{:?}", array);
}
}
[1, 2, 3]
[1, 2, 3]
[1, 2, 3]
[1, 2, 3]
[1, 2, 3]
[1, 2, 3]
[1, 2, 3]
[1, 2, 3]
[1, 2, 3]
[1, 2, 3]