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,

source

pub fn new() -> Self

Creates a new keyed arena.

source

pub fn with_capacity(size: usize) -> Self

Creates a new keyed arena with the given capacity.

source

pub fn len(&self) -> usize

Returns the number of elements owned by the arena.

source

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.

source

pub fn reserve(&self, additional: usize)

Ensures there is enough continuous space for at least additional values.

source

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.

KeyedArenas 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.

source

pub fn keys(&mut self) -> impl Iterator<Item = &K>

Returns an iterator over all keys in the arena.

source

pub fn values_mut(&mut self) -> impl Iterator<Item = &mut T>

Returns an iterator over mutable references to all elements in the arena.

source

pub fn get_mut<R>(&self, key: &R) -> Option<&mut T>
where K: Borrow<R>, R: Key + ?Sized,

Returns a mutable reference to a value previously inserted into the arena.

source

pub fn get<R>(&self, key: &R) -> Option<&T>
where K: Borrow<R>, R: Key + ?Sized,

Returns a reference to a value previously inserted into the arena.

source

pub fn contains_key<R>(&self, key: &R) -> bool
where K: Borrow<R>, R: Key + ?Sized,

Checks if the arena contains a value for the given key.

Auto Trait Implementations§

§

impl<K, T> !RefUnwindSafe for KeyedArena<K, T>

§

impl<K, T> !Send for KeyedArena<K, T>

§

impl<K, T> !Sync for KeyedArena<K, T>

§

impl<K, T> Unpin for KeyedArena<K, T>
where K: Unpin, T: Unpin,

§

impl<K, T> UnwindSafe for KeyedArena<K, T>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.