Arena

Struct Arena 

Source
pub struct Arena<T> { /* private fields */ }
Expand description

A container of items that can be accessed via a Key.

Implementations§

Source§

impl<T> Arena<T>

Source

pub fn new(capacity: usize) -> Self

Creates a new Arena with enough space for capacity number of items.

Source

pub fn controller(&self) -> Controller

Returns a Controller for this Arena.

Source

pub fn capacity(&self) -> usize

Returns the total capacity for this Arena.

Source

pub fn len(&self) -> usize

Returns the number of items currently in the Arena.

Source

pub fn is_empty(&self) -> bool

Returns true if the Arena is currently empty.

Source

pub fn insert_with_key( &mut self, key: Key, data: T, ) -> Result<(), InsertWithKeyError>

Tries to insert an item into the Arena with a previously reserved Key.

Source

pub fn insert(&mut self, data: T) -> Result<Key, ArenaFull>

Tries to reserve a Key, and, if successful, inserts an item into the Arena with that Key and returns the Key.

Source

pub fn remove(&mut self, key: Key) -> Option<T>

If the Arena contains an item with the given Key, removes it from the Arena and returns Some(item). Otherwise, returns None.

Source

pub fn get(&self, key: Key) -> Option<&T>

Returns a shared reference to the item in the Arena with the given Key if it exists. Otherwise, returns None.

Source

pub fn get_mut(&mut self, key: Key) -> Option<&mut T>

Returns a mutable reference to the item in the Arena with the given Key if it exists. Otherwise, returns None.

Source

pub fn retain(&mut self, f: impl FnMut(&T) -> bool)

Retains only the elements specified by the predicate.

In other words, remove all elements e such that f(&e) returns false.

Source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over shared references to the items in the Arena.

The most recently added items will be visited first.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns an iterator over mutable references to the items in the Arena.

The most recently added items will be visited first.

Source

pub fn drain_filter<F: FnMut(&T) -> bool>( &mut self, filter: F, ) -> DrainFilter<'_, T, F>

Returns an iterator that removes and yields all elements for which filter(&element) returns true.

Trait Implementations§

Source§

impl<T: Debug> Debug for Arena<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Index<Key> for Arena<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, key: Key) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<Key> for Arena<T>

Source§

fn index_mut(&mut self, key: Key) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, T> IntoIterator for &'a Arena<T>

Source§

type Item = (Key, &'a T)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T> IntoIterator for &'a mut Arena<T>

Source§

type Item = (Key, &'a mut T)

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

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> UnwindSafe for Arena<T>
where T: UnwindSafe,

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>,

Source§

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>,

Source§

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.