Struct triple_arena::Arena[][src]

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

An arena containing elements (that can be non-Clone) that can be pointed to by TriPtrs. This is a kind of generational arena that allows deletion and inter-arena references (even between Arena<T>s of completely different T).

Implementations

impl<T> Arena<T>[src]

Note

A TriPtr is invalid if:

  • it points to a different arena than the one it is being used as an argument to
  • it points to an element that has been removed or has otherwise been the target of some pointer invalidation operation

pub fn new() -> Arena<T>[src]

Creates a new arena that can contain elements of type T. Note: this function makes atomic fetches.

pub fn id(&self) -> NonZeroU64[src]

Returns the unique id of this arena

pub fn len(&self) -> usize[src]

Returns the number of elements in the arena

pub fn is_empty(&self) -> bool[src]

Returns if the arena is empty

pub fn capacity(&self) -> usize[src]

Returns the capacity of the arena

pub fn try_insert(&mut self, e: T) -> Result<TriPtr, T>[src]

Tries to insert element e into the arena without changing its capacity.

Errors

Returns ownership of e if there are no remaining unallocated entries in the arena.

pub fn try_insert_with<F: FnOnce() -> T>(
    &mut self,
    create: F
) -> Result<TriPtr, F>
[src]

Tries to insert the element created by create into the arena without changing its capacity.

Errors

Does not run create and returns ownership if there are no remaining unallocated entries in the arena.

pub fn insert(&mut self, e: T) -> TriPtr[src]

Inserts element e into the arena and returns a TriPtr to it. If more capacity is needed, the Arena reallocates in powers of two.

pub fn get(&self, p: TriPtr) -> Option<&T>[src]

Returns an immutable reference to the element pointed to by p. Returns None if p is invalid.

pub fn get_mut(&mut self, p: TriPtr) -> Option<&mut T>[src]

Returns a mutable reference to the element pointed to by p. Returns None if p is invalid.

pub fn invalidate(&mut self, p: TriPtr) -> Option<TriPtr>[src]

Invalidates all references to the element pointed to by p, and returns a new valid reference. Does no invalidation and returns None if p is invalid.

pub fn replace_keep_gen(&mut self, p: TriPtr, new: T) -> Result<T, T>[src]

Replaces the element pointed to by p with new, returns the old element, and keeps the internal generation counter as-is so that previously constructed TriPtrs to this entry are still valid.

Errors

Returns ownership of new instead if p is invalid

pub fn replace_update_gen(
    &mut self,
    p: TriPtr,
    new: T
) -> Result<(TriPtr, T), T>
[src]

Replaces the element pointed to by p with new, returns a tuple of the new pointer and old element, and updates the internal generation counter so that previously constructed TriPtrs to this entry are invalidated.

Errors

Does no invalidation and returns ownership of new instead if p is invalid

pub fn remove(&mut self, p: TriPtr) -> Option<T>[src]

Removes the element pointed to by p, returns the element, and invalidates old TriPtrs to the element. Does no invalidation and returns None if p is invalid.

pub fn clear(&mut self)[src]

Clears all elements from the arena and invalidates all pointers previously created from it. Note that this has no effect on allocated capacity.

Trait Implementations

impl<T: Debug> Debug for Arena<T>[src]

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

Formats the value using the given formatter. Read more

impl<T> Default for Arena<T>[src]

fn default() -> Self[src]

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

Auto Trait Implementations

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.