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]
impl<H, T> SupplementalArena<H, T>
[src]pub fn new() -> 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]
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.
impl<H, T> SupplementalArena<H, T> where
T: Default,
[src]
impl<H, T> SupplementalArena<H, T> where
T: Default,
[src]pub fn get_mut_or_default(&mut self, handle: Handle<H>) -> &mut T
[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]
impl<H, T> Default for SupplementalArena<H, T>
[src]fn default() -> 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]
impl<H, T> Index<Handle<H>> for SupplementalArena<H, T>
[src]Auto Trait Implementations
impl<H, T> RefUnwindSafe for SupplementalArena<H, T> where
H: RefUnwindSafe,
T: RefUnwindSafe,
H: RefUnwindSafe,
T: RefUnwindSafe,
impl<H, T> Send for SupplementalArena<H, T> where
H: Send,
T: Send,
H: Send,
T: Send,
impl<H, T> Sync for SupplementalArena<H, T> where
H: Sync,
T: Sync,
H: Sync,
T: Sync,
impl<H, T> Unpin for SupplementalArena<H, T> where
H: Unpin,
T: Unpin,
H: Unpin,
T: Unpin,
impl<H, T> UnwindSafe for SupplementalArena<H, T> where
H: UnwindSafe,
T: UnwindSafe,
H: UnwindSafe,
T: UnwindSafe,