Expand description
A contiguous growable array type with heap-allocated contents, written
Vec<'bump, T>.
Vectors have O(1) indexing, amortized O(1) push (to the end) and
O(1) pop (from the end).
This module is a fork of the std::vec module, that uses a bump allocator.
§Examples
You can explicitly create a Vec<'bump, T> with new_in:
use bumpalo::{Bump, collections::Vec};
let b = Bump::new();
let v: Vec<i32> = Vec::new_in(&b);… or by using the vec! macro:
use bumpalo::{Bump, collections::Vec};
let b = Bump::new();
let v: Vec<i32> = bumpalo::vec![in &b];
let v = bumpalo::vec![in &b; 1, 2, 3, 4, 5];
let v = bumpalo::vec![in &b; 0; 10]; // ten zeroesYou can push values onto the end of a vector (which will grow the vector
as needed):
use bumpalo::{Bump, collections::Vec};
let b = Bump::new();
let mut v = bumpalo::vec![in &b; 1, 2];
v.push(3);Popping values works in much the same way:
use bumpalo::{Bump, collections::Vec};
let b = Bump::new();
let mut v = bumpalo::vec![in &b; 1, 2];
assert_eq!(v.pop(), Some(2));Vectors also support indexing (through the Index and IndexMut traits):
use bumpalo::{Bump, collections::Vec};
let b = Bump::new();
let mut v = bumpalo::vec![in &b; 1, 2, 3];
assert_eq!(v[2], 3);
v[1] += 5;
assert_eq!(v, [1, 7, 3]);Structs§
- Drain
- A draining iterator for
Vec<'bump, T>. - Drain
Filter - An iterator produced by calling
Vec::drain_filter. - Into
Iter - An iterator that moves out of a vector.
- Splice
- A splicing iterator for
Vec. - Vec
- A contiguous growable array type, written
Vec<'bump, T>but pronounced ‘vector’.