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

Creates a new, empty supplemental arena.

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.

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

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

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

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

The returned type after indexing.

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

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.