How to use Vec in Rust

Create a dynamic list in Rust using Vec::new() or the vec! macro to store and manage collections of same-type values.

Use Vec::new() to create an empty vector or vec![] to create one with initial values. Vectors store elements of the same type on the heap and grow dynamically.

fn main() {
    let empty: Vec<i32> = Vec::new();
    let with_data: Vec<i32> = vec![1, 2, 3];
    let mut v = with_data;
    v.push(4);
}