[Rust] Vectors in Rust
In this lesson you'll learn about Vec<T>
, or Vectors. Vectors are like Arrays, a collection of values of the same type, but as opposed to Arrays, Vectors can change in size.
#[allow(warnings)]
fn main() {
let mut numbers = vec![1, 4];
numbers.push(3);
numbers.push(2);
for number in &numbers {
println!("{}", number)
}
}
Another way to create Vector:
let mut numbers = Vec::new();
numbers.push(1);
numbers.push(2);