Expand description
A growable array type with values persisted to storage and lazily loaded.
Values in the Vector
are kept in an in-memory cache and are only persisted on Drop
.
Vectors ensure they never allocate more than u32::MAX
bytes. u32
is used rather than
usize
as in Vec
to ensure consistent behavior on different targets.
§Examples
You can explicitly create a Vector
with Vector::new
:
use near_sdk::store::Vector;
let v: Vector<i32> = Vector::new(b"a");
You can push
values onto the end of a vector (which will grow the vector
as needed):
use near_sdk::store::Vector;
let mut v: Vector<i32> = Vector::new(b"a");
v.push(3);
Popping values works in much the same way:
use near_sdk::store::Vector;
let mut v: Vector<i32> = Vector::new(b"a");
v.extend([1, 2]);
let two = v.pop();
Vectors also support indexing (through the Index
and IndexMut
traits):
use near_sdk::store::Vector;
let mut v: Vector<i32> = Vector::new(b"a");
v.extend([1, 2, 3]);
let three = v[2];
v[1] = v[1] + 5;
Structs§
- Drain
- A draining iterator for
Vector<T>
. - Iter
- An iterator over references to each element in the stored vector.
- IterMut
- An iterator over exclusive references to each element of a stored vector.
- Vector
- An iterable implementation of vector that stores its content on the trie. This implementation will load and store values in the underlying storage lazily.