std-type
Vec<T> — owned sequence
Use Vec when you need an owned, variable-length sequence of values of one element type. Indexing accesses a position in constant time; insertion in the middle may shift later elements. For non-zero-sized elements, nonzero capacity uses an allocation. Empty vectors can avoid allocation. Expected stdout (not executed): 3 ship Common mistake: Confusing Vec<T> with &[T], which borrows a sequence rather than owning its elements.
Formal Syntax & Structure
rust syntaxrust
Vec<T>Working Example
Example Snippetrust
fn main() { let mut tasks: Vec<String> = vec!["read".into(), "test".into()]; tasks.push("ship".into()); println!("{} {}", tasks.len(), tasks[2]);}