- mut
- push
- append
Mutable vector of numbers, append (push) values
- We can make a vector mutable by using the mut keyword.
- We can append an element to the end of the vector using the push method.
examples/vectors/mutable-numbers-vector/src/main.rs
fn main() { let mut numbers = vec![10, 11, 12]; println!("{}", numbers.len()); println!("{:?}", numbers); numbers.push(23); println!("{}", numbers.len()); println!("{:?}", numbers); }
3 [10, 11, 12] 4 [10, 11, 12, 23]