pub struct SmallArena<'tag, T> { /* private fields */ }Expand description
A “Small” arena based on a resizable slice (i.e. a Vec) that can be
indexed with 32-bit Idx32s. This can help reduce memory overhead when
using many pointer-heavy objects on 64-bit systems.
You can obtain an instance of this type by calling mk_arena.
Implementations§
Source§impl<'tag, T> SmallArena<'tag, T>
impl<'tag, T> SmallArena<'tag, T>
Sourcepub unsafe fn new(tag: InvariantLifetime<'tag>, capacity: usize) -> Self
pub unsafe fn new(tag: InvariantLifetime<'tag>, capacity: usize) -> Self
create a new SmallArena. Don’t do this manually. Use the
in_arena macro instead.
§Safety
The whole tagged indexing trick relies on the 'tag you give to this
constructor. You must never use this value in another arena, lest you
might be able to mix up the indices of the two, which could lead to
out of bounds access and thus Undefined Behavior!
Sourcepub unsafe fn from_vec(tag: InvariantLifetime<'tag>, data: Vec<T>) -> Self
pub unsafe fn from_vec(tag: InvariantLifetime<'tag>, data: Vec<T>) -> Self
move a Vec into a SmallArena. This is unlikely to be useful to you,
it’s an implementation detail of the recycle_arena! macro.
Sourcepub fn into_inner(self) -> Vec<T>
pub fn into_inner(self) -> Vec<T>
consume the arena and get the data out
Sourcepub fn try_add(&mut self, item: T) -> Result<Idx32<'tag>, CapacityExceeded<T>>
pub fn try_add(&mut self, item: T) -> Result<Idx32<'tag>, CapacityExceeded<T>>
Add an item to the arena, get an index or CapacityExceeded back.
Sourcepub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
View the current elements as a slice.
§Examples
mk_arena!(arena);
let _ = arena.add("Hi!");
let _ = arena.add("Bye!");
assert_eq!(&["Hi!", "Bye!"], arena.as_slice());Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Mutate the current elements as a slice.
§Examples
mk_arena!(arena);
let one = arena.add(1u32);
let two = arena.add(2);
arena.as_mut_slice().into_iter().for_each(|i| *i += 1);
assert_eq!(arena[one], 2);
assert_eq!(arena[two], 3);