Struct zone_alloc::KeyedArena
source · pub struct KeyedArena<K, T> { /* private fields */ }
Expand description
The same as Arena<T>
, but each inserted value is internally mapped to a custom key for
retrieving the value later.
Similar to crate::Registry
, except a KeyMap
is used internally, which requires key
hashing or ordering. Hashing is used by default. In no_std
builds, ordering is used.
Implementations§
source§impl<K, T> KeyedArena<K, T>where
K: Key,
impl<K, T> KeyedArena<K, T>where
K: Key,
sourcepub fn with_capacity(size: usize) -> Self
pub fn with_capacity(size: usize) -> Self
Creates a new keyed arena with the given capacity.
sourcepub fn insert(&self, key: K, value: T) -> Option<&mut T>
pub fn insert(&self, key: K, value: T) -> Option<&mut T>
Inserts a new value in the arena, returning a mutable reference to that vaue.
Returns None
if a value already exists for key
.
sourcepub fn reserve(&self, additional: usize)
pub fn reserve(&self, additional: usize)
Ensures there is enough continuous space for at least additional
values.
sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, T>
pub fn iter_mut(&mut self) -> IterMut<'_, K, T>
Returns an iterator that provides mutable access to all elements in the arena.
There is no guaranteed order of entries.
KeyedArena
s only allow mutable iteration because the entire arena must be borrowed for
the duration of the iteration. The mutable borrow to call this method allows Rust’s
borrow checker to enforce this rule.
sourcepub fn keys(&mut self) -> impl Iterator<Item = &K>
pub fn keys(&mut self) -> impl Iterator<Item = &K>
Returns an iterator over all keys in the arena.
sourcepub fn values_mut(&mut self) -> impl Iterator<Item = &mut T>
pub fn values_mut(&mut self) -> impl Iterator<Item = &mut T>
Returns an iterator over mutable references to all elements in the arena.
sourcepub fn get_mut<R>(&self, key: &R) -> Option<&mut T>
pub fn get_mut<R>(&self, key: &R) -> Option<&mut T>
Returns a mutable reference to a value previously inserted into the arena.