pub struct Arena<K, T, const N: usize>where
K: Kind,{ /* private fields */ }Expand description
N slots of T, addressed by generational Handle<K>.
Implementations§
Source§impl<K, T, const N: usize> Arena<K, T, N>where
K: Kind,
impl<K, T, const N: usize> Arena<K, T, N>where
K: Kind,
Sourcepub fn insert(&mut self, value: T) -> Result<Handle<K>, Error>
pub fn insert(&mut self, value: T) -> Result<Handle<K>, Error>
Place value in a free slot and return its handle.
§Errors
Error::NoMemory when every slot is occupied; the value is
returned to the caller inside the error’s companion so nothing is
lost — see Arena::try_insert.
Sourcepub fn try_insert(&mut self, value: T) -> Result<Handle<K>, T>
pub fn try_insert(&mut self, value: T) -> Result<Handle<K>, T>
Like Arena::insert, but hands the value back when there is no room.
§Errors
The value itself, when every slot is occupied.
Sourcepub fn get_mut(&mut self, handle: Handle<K>) -> Option<&mut T>
pub fn get_mut(&mut self, handle: Handle<K>) -> Option<&mut T>
The object handle names, mutably.
Sourcepub fn resolve(&self, handle: Handle<K>) -> Result<&T, Error>
pub fn resolve(&self, handle: Handle<K>) -> Result<&T, Error>
Like Arena::get, but says why: Error::InvalidHandle for the
null handle or an index beyond the arena, Error::Gone for a
generation that has been reused or freed.
§Errors
As above.
Sourcepub fn remove(&mut self, handle: Handle<K>) -> Option<T>
pub fn remove(&mut self, handle: Handle<K>) -> Option<T>
Remove the object handle names, invalidating the handle and every
copy of it.
Sourcepub fn iter(&self) -> impl Iterator<Item = (Handle<K>, &T)>
pub fn iter(&self) -> impl Iterator<Item = (Handle<K>, &T)>
Every live (handle, object) in slot order.
Trait Implementations§
Auto Trait Implementations§
impl<K, T, const N: usize> Freeze for Arena<K, T, N>
impl<K, T, const N: usize> RefUnwindSafe for Arena<K, T, N>
impl<K, T, const N: usize> Send for Arena<K, T, N>
impl<K, T, const N: usize> Sync for Arena<K, T, N>
impl<K, T, const N: usize> Unpin for Arena<K, T, N>
impl<K, T, const N: usize> UnsafeUnpin for Arena<K, T, N>
impl<K, T, const N: usize> UnwindSafe for Arena<K, T, N>
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