- vec
- len
Fixed vector of numbers
- A Vec vector is a series of values of the same type.
- We can initialize a vector using the vec! macro.
- We can get the length of the vector using the len method.
- We cannot print a vector with the simle {} placeholder because Display is not implemented for it.
- However we can use the {:?} or the {:#?} placeholders.
- By default vectors are immutable.
examples/vectors/numbers/src/main.rs
fn main() { let numbers = vec![10, 11, 12]; println!("{}", numbers.len()); // println!("{}", numbers); // `Vec<{integer}>` doesn't implement `std::fmt::Display` // `Vec<{integer}>` cannot be formatted with the default formatter println!("{:?}", numbers); println!("{:#?}", numbers); }
3 [10, 11, 12] [ 10, 11, 12, ]