Skip to main content

GenerationalArena

Struct GenerationalArena 

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

An arena that tracks generations for safe index validation.

When an element is removed, the slot’s generation is incremented. Indices store the generation they were created with, so stale references can be detected.

Implementations§

Source§

impl<T> GenerationalArena<T>

Source

pub fn new() -> Self

Create a new generational arena.

Source

pub fn with_capacity(cap: usize) -> Self

Create with pre-allocated capacity.

Source

pub fn insert(&mut self, value: T) -> GenIdx

Insert a value and get its index.

Source

pub fn get(&self, idx: GenIdx) -> Option<&T>

Get a reference to a value by generational index.

Source

pub fn get_mut(&mut self, idx: GenIdx) -> Option<&mut T>

Get a mutable reference to a value by generational index.

Source

pub fn remove(&mut self, idx: GenIdx) -> Option<T>

Remove a value by generational index.

Source

pub fn contains(&self, idx: GenIdx) -> bool

Check if an index is valid.

Source

pub fn len(&self) -> usize

Number of live entries.

Source

pub fn is_empty(&self) -> bool

Check if empty.

Source

pub fn clear(&mut self)

Clear all entries.

Source

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

Iterate over live entries.

Trait Implementations§

Source§

impl<T: Debug> Debug for GenerationalArena<T>

Source§

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

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

impl<T> Default for GenerationalArena<T>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<T> Freeze for GenerationalArena<T>

§

impl<T> RefUnwindSafe for GenerationalArena<T>
where T: RefUnwindSafe,

§

impl<T> Send for GenerationalArena<T>
where T: Send,

§

impl<T> Sync for GenerationalArena<T>
where T: Sync,

§

impl<T> Unpin for GenerationalArena<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for GenerationalArena<T>

§

impl<T> UnwindSafe for GenerationalArena<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.