Struct stack_graphs::arena::SupplementalArena[][src]

pub struct SupplementalArena<H, T> { /* fields omitted */ }
Expand description

A supplemental arena lets you store additional data about some data type that is itself stored in an Arena.

We implement Index and IndexMut for a more ergonomic syntax. Please note that when indexing in an immutable context, we panic if you try to access data for a handle that doesn’t exist in the arena. (Use the get method if you don’t know whether the value exists or not.) In a mutable context, we automatically create a Default instance of the type if there isn’t already an instance for that handle in the arena.

// We need an Arena to create handles.
let mut arena = Arena::<u32>::new();
let handle = arena.add(1);

let mut supplemental = SupplementalArena::<u32, String>::new();

// But indexing will panic if the element doesn't already exist.
// assert_eq!(supplemental[handle].as_str(), "");

// The `get` method is always safe, since it returns an Option.
assert_eq!(supplemental.get(handle), None);

// Once we've added the element to the supplemental arena, indexing
// won't panic anymore.
supplemental[handle] = "hello".to_string();
assert_eq!(supplemental[handle].as_str(), "hello");

Implementations

impl<H, T> SupplementalArena<H, T>[src]

pub fn new() -> SupplementalArena<H, T>[src]

Creates a new, empty supplemental arena.

pub fn with_capacity(arena: &Arena<H>) -> SupplementalArena<H, T>[src]

Creates a new, empty supplemental arena, preallocating enough space to store supplemental data for all of the instances that have already been allocated in a (regular) arena.

pub fn get(&self, handle: Handle<H>) -> Option<&T>[src]

Returns the item belonging to a particular handle, if it exists.

pub fn get_mut(&mut self, handle: Handle<H>) -> Option<&mut T>[src]

Returns a mutable reference to the item belonging to a particular handle, if it exists.

impl<H, T> SupplementalArena<H, T> where
    T: Default
[src]

pub fn get_mut_or_default(&mut self, handle: Handle<H>) -> &mut T[src]

Returns a mutable reference to the item belonging to a particular handle, creating it first (using the type’s Default implementation) if it doesn’t already exist.

Trait Implementations

impl<H, T> Default for SupplementalArena<H, T>[src]

fn default() -> SupplementalArena<H, T>[src]

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

impl<H, T> Index<Handle<H>> for SupplementalArena<H, T>[src]

type Output = T

The returned type after indexing.

fn index(&self, handle: Handle<H>) -> &T[src]

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

impl<H, T> IndexMut<Handle<H>> for SupplementalArena<H, T> where
    T: Default
[src]

fn index_mut(&mut self, handle: Handle<H>) -> &mut T[src]

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

Auto Trait Implementations

impl<H, T> RefUnwindSafe for SupplementalArena<H, T> where
    H: RefUnwindSafe,
    T: RefUnwindSafe

impl<H, T> Send for SupplementalArena<H, T> where
    H: Send,
    T: Send

impl<H, T> Sync for SupplementalArena<H, T> where
    H: Sync,
    T: Sync

impl<H, T> Unpin for SupplementalArena<H, T> where
    H: Unpin,
    T: Unpin

impl<H, T> UnwindSafe for SupplementalArena<H, T> where
    H: UnwindSafe,
    T: UnwindSafe

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.