Struct generational_cache::arena::Arena
source · pub struct Arena<V, T> { /* private fields */ }Expand description
A generational arena for allocating memory based off a vector. Every entry is associated with a generation counter to uniquely identify newer allocations from older reclaimed allocations at the same position in the vector.
This is inspired from the crate “generational-arena”
Usage
#[no_std]
use generational_cache::prelude::*;
const CAPACITY: usize = 5;
let mut arena = Arena::<_, i32>::with_vector(Array::<_, CAPACITY>::new());
let index = arena.insert(78).unwrap(); // allocate new element in arena
let i_ref = arena.get(&index);
assert_eq!(i_ref, Some(&78));
let i_m_ref = arena.get_mut(&index).unwrap();
*i_m_ref = -68418;
assert_eq!(arena.get(&index), Some(&-68418));
arena.remove(&index).unwrap();
assert!(arena.get(&index).is_none());Implementations§
source§impl<V, T> Arena<V, T>where
V: Vector<Entry<T>>,
impl<V, T> Arena<V, T>where V: Vector<Entry<T>>,
A generational arena.
pub fn clear(&mut self) -> Result<(), ArenaError<V::Error>>
pub fn with_vector(vector: V) -> Self
pub fn insert(&mut self, item: T) -> Result<Index, ArenaError<V::Error>>
pub fn remove(&mut self, index: &Index) -> Option<T>
pub fn get_mut(&mut self, index: &Index) -> Option<&mut T>
pub fn get(&self, index: &Index) -> Option<&T>
pub fn capacity(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
Auto Trait Implementations§
impl<V, T> RefUnwindSafe for Arena<V, T>where T: RefUnwindSafe, V: RefUnwindSafe,
impl<V, T> Send for Arena<V, T>where T: Send, V: Send,
impl<V, T> Sync for Arena<V, T>where T: Sync, V: Sync,
impl<V, T> Unpin for Arena<V, T>where T: Unpin, V: Unpin,
impl<V, T> UnwindSafe for Arena<V, T>where T: UnwindSafe, V: 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