Module std::vec

Storing Lists of Values with Vectors

The first collection type we’ll look at is Vec, also known as a vector. Vectors allow you to store more than one value in a single data structure that puts all the values next to each other in memory. Vectors can only store values of the same type. They are useful when you have a list of items, such as the lines of text in a file or the prices of items in a shopping cart.

Creating a New Vector

To create a new, empty vector, we can call the Vec::new function,

fn main() {
    let v: Vec<i32> = Vec::new();
}