A Vec<T> stores many values of one type. It can grow with push and be summed with an iterator.

Program

Play the program to push a value and total the vector.

vectors.rs
fn main() {
    let mut nums = vec![1, 2, 3];
    nums.push(4);
    let total: i32 = nums.iter().sum();
    println!("{total}");
}
vec! `vec![1, 2, 3]` builds a vector with initial values.
push `push` appends one value to the end.
iter().sum() `iter().sum()` adds every element.