Vec
implements , which means that you can call slice methods on a Vec
.
Vec
is a type of collection, along withString
andHashMap
. The data it contains is stored on the heap. This means the amount of data doesn’t need to be known at compile time. It can grow or shrink at runtime.vec![...]
is a canonical macro to use instead of and it supports adding initial elements to the vector.- Show iterating over a vector and mutating the value:
for e in &mut v { *e += 50; }