pub struct SupplementalArena<H, T> { /* private fields */ }
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 the number of instances stored in this arena.

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
Executes the destructor for this 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
Converts self into T using Into<T>. Read more
Causes self to use its Binary implementation when Debug-formatted.
Causes self to use its Display implementation when Debug-formatted.
Causes self to use its LowerExp implementation when Debug-formatted.
Causes self to use its LowerHex implementation when Debug-formatted.
Causes self to use its Octal implementation when Debug-formatted.
Causes self to use its Pointer implementation when Debug-formatted.
Causes self to use its UpperExp implementation when Debug-formatted.
Causes self to use its UpperHex implementation when Debug-formatted.
Formats each item in a sequence. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Pipes by value. This is generally the method you want to use. Read more
Borrows self and passes that borrow into the pipe function. Read more
Mutably borrows self and passes that borrow into the pipe function. Read more
Borrows self, then passes self.borrow() into the pipe function. Read more
Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Borrows self, then passes self.as_ref() into the pipe function.
Mutably borrows self, then passes self.as_mut() into the pipe function.
Borrows self, then passes self.deref() into the pipe function.
Mutably borrows self, then passes self.deref_mut() into the pipe function.
Immutable access to a value. Read more
Mutable access to a value. Read more
Immutable access to the Borrow<B> of a value. Read more
Mutable access to the BorrowMut<B> of a value. Read more
Immutable access to the AsRef<R> view of a value. Read more
Mutable access to the AsMut<R> view of a value. Read more
Immutable access to the Deref::Target of a value. Read more
Mutable access to the Deref::Target of a value. Read more
Calls .tap() only in debug builds, and is erased in release builds.
Calls .tap_mut() only in debug builds, and is erased in release builds.
Calls .tap_borrow() only in debug builds, and is erased in release builds.
Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Calls .tap_ref() only in debug builds, and is erased in release builds.
Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Calls .tap_deref() only in debug builds, and is erased in release builds.
Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Attempts to convert self into T using TryInto<T>. Read more
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.