pub struct Arena<T> { /* private fields */ }Expand description
A typed arena for storing values contiguously.
Values are never moved once allocated, so references remain valid for the lifetime of the arena.
Implementations§
Source§impl<T> Arena<T>
impl<T> Arena<T>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new arena with the specified capacity.
Sourcepub fn alloc(&mut self, value: T) -> Idx<T>
pub fn alloc(&mut self, value: T) -> Idx<T>
Allocate a value in the arena and return its index.
Sourcepub fn alloc_many(&mut self, values: impl IntoIterator<Item = T>) -> IdxRange<T>
pub fn alloc_many(&mut self, values: impl IntoIterator<Item = T>) -> IdxRange<T>
Allocate multiple values at once, returning the index range.
Sourcepub fn get(&self, idx: Idx<T>) -> &T
pub fn get(&self, idx: Idx<T>) -> &T
Get a reference to the value at the given index.
§Panics
Panics if the index is out of bounds (in debug mode).
Sourcepub fn get_mut(&mut self, idx: Idx<T>) -> &mut T
pub fn get_mut(&mut self, idx: Idx<T>) -> &mut T
Get a mutable reference to the value at the given index.
Sourcepub fn iter_indexed(&self) -> impl Iterator<Item = (Idx<T>, &T)>
pub fn iter_indexed(&self) -> impl Iterator<Item = (Idx<T>, &T)>
Iterate over all (index, value) pairs.
Sourcepub fn stats(&self) -> ArenaStats
pub fn stats(&self) -> ArenaStats
Collect the current size statistics.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrink the arena’s backing storage to fit.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Arena<T>
impl<T> RefUnwindSafe for Arena<T>where
T: RefUnwindSafe,
impl<T> Send for Arena<T>where
T: Send,
impl<T> Sync for Arena<T>where
T: Sync,
impl<T> Unpin for Arena<T>where
T: Unpin,
impl<T> UnsafeUnpin for Arena<T>
impl<T> UnwindSafe for Arena<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more