Expand description
A contiguous growable array type with heap-allocated contents, written
Vec<T>
.
Vectors have O(1) indexing, amortized O(1) push (to the end) and O(1) pop (from the end).
Vectors ensure they never allocate more than isize::MAX
bytes.
Β§Examples
You can explicitly create a Vec
with Vec::new
:
let v: Vec<i32> = Vec::new();
β¦or by using the vec!
macro:
let v: Vec<i32> = vec![];
let v = vec![1, 2, 3, 4, 5];
let v = vec![0; 10]; // ten zeroes
You can push
values onto the end of a vector (which will grow the vector
as needed):
let mut v = vec![1, 2];
v.push(3);
Popping values works in much the same way:
let mut v = vec![1, 2];
let two = v.pop();
Vectors also support indexing (through the Index
and IndexMut
traits):
let mut v = vec![1, 2, 3];
let three = v[2];
v[1] = v[1] + 5;
Re-exportsΒ§
ModulesΒ§
- drain π
- into_
iter π - partial_
eq π - set_
len_ πon_ drop - splice π
StructsΒ§
- Extend
Element π - InPlace
Seed - A DeserializeSeed helper for implementing deserialize_in_place Visitors.
- Vec
- A contiguous growable array type, written as
Vec<T>
, short for βvectorβ.
TraitsΒ§
- Extend
With π