Skip to main content

Arena

Struct Arena 

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

A minimal generational arena (house rule: 40 boring lines beat a dependency). Slots are reused; each reuse bumps the generation.

Implementations§

Source§

impl<K, T> Arena<K, T>

Source

pub fn insert(&mut self, value: T) -> Id<K>

Source

pub fn get(&self, id: Id<K>) -> Option<&T>

None for a stale id — never the wrong document.

Source

pub fn get_mut(&mut self, id: Id<K>) -> Option<&mut T>

Source

pub fn remove(&mut self, id: Id<K>) -> Option<T>

Remove and return the value; stale ids get None.

Source

pub fn iter(&self) -> impl Iterator<Item = (Id<K>, &T)>

Source

pub fn len(&self) -> usize

Source

pub fn clear(&mut self)

Drop every live value (slot reuse still bumps generations).

Source

pub fn is_empty(&self) -> bool

Trait Implementations§

Source§

impl<K, T> Default for Arena<K, T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<K, T> Freeze for Arena<K, T>
where Vec<Slot<T>>: Freeze, PhantomData<K>: Freeze,

§

impl<K, T> RefUnwindSafe for Arena<K, T>

§

impl<K, T> Send for Arena<K, T>
where Vec<Slot<T>>: Send, PhantomData<K>: Send,

§

impl<K, T> Sync for Arena<K, T>
where Vec<Slot<T>>: Sync, PhantomData<K>: Sync,

§

impl<K, T> Unpin for Arena<K, T>
where Vec<Slot<T>>: Unpin, PhantomData<K>: Unpin,

§

impl<K, T> UnsafeUnpin for Arena<K, T>
where Vec<Slot<T>>: UnsafeUnpin, PhantomData<K>: UnsafeUnpin,

§

impl<K, T> UnwindSafe for Arena<K, T>
where Vec<Slot<T>>: UnwindSafe, PhantomData<K>: 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.