Basic Vector Manipulation in Rust
Explore the fundamentals of working with vectors in Rust, including adding, removing, and iterating over elements.
Explore the fundamentals of working with vectors in Rust, including adding, removing, and iterating over elements.
fn main() {
let mut numbers = vec![1, 2, 3, 4, 5];
// Add an element to the end of the vector
numbers.push(6);
// Remove the last element from the vector
let popped = numbers.pop();
// Iterate over the elements
for number in &numbers {
println!("{}", number);
}
}