published: 20th of February 2022
A vector is a collection of items of the same type.
// Create an empty mutable empty vector.
// The type of the elements must be annotated.
let mut stuff_and_things: Vec<&str> = Vec::new();
// Add items to the vector.
stuff_and_things.push("stuff");
stuff_and_things.push("things");
// Access the elements of a vector with square brackets and the index number.
println!("{}", stuff_and_things[0]); // => stuff
println!("{}", stuff_and_things[1]); // => things
// Accessing an element that is out of bounds will result in a panic.
println!("{}", stuff_and_things[2]); // => PANIC!
// Create an immutable vector with 2 elements using the literal syntax.
let stuff_and_things = vec!["stuff", "things"];
// Specify the type annotation
let stuff_and_things: Vec<&str> = vec!["stuff", "things"];
// Create a mutable vector with the literal syntax
let mut stuff_and_things = vec!["stuff", "things"];
https://www.manning.com/books/rust-in-action
https://www.udemy.com/course/ultimate-rust-crash-course/