Struct netsblox_vm::slotmap::SlotMap
source · pub struct SlotMap<K: Key, T> { /* private fields */ }Expand description
A dense, resizable array that supports generational indexing.
You can use the [new_key] macro to create a new key type to use.
It is recommended to use different key types for different collections to avoid accidentally using a key from a different map.
Implementations§
source§impl<K: Key, T> SlotMap<K, T>
impl<K: Key, T> SlotMap<K, T>
sourcepub fn insert(&mut self, value: T) -> K
pub fn insert(&mut self, value: T) -> K
Adds a new value to the map and returns a new key that references it.
sourcepub fn remove(&mut self, key: K) -> Option<T>
pub fn remove(&mut self, key: K) -> Option<T>
Removes a value from the map and returns it (if it existed).
It is guaranteed that all future accesses with the removed key will return None.
sourcepub fn get_mut(&mut self, key: K) -> Option<&mut T>
pub fn get_mut(&mut self, key: K) -> Option<&mut T>
Get a mutable reference to a value in the map.
Trait Implementations§
source§impl<K: Key, T> Collect for SlotMap<K, T>where
Vec<usize>: 'static,
usize: 'static,
PhantomData<K>: 'static,
T: Collect,
impl<K: Key, T> Collect for SlotMap<K, T>where Vec<usize>: 'static, usize: 'static, PhantomData<K>: 'static, T: Collect,
source§fn needs_trace() -> bool
fn needs_trace() -> bool
As an optimization, if this type can never hold a
Gc pointer and trace is unnecessary
to call, you may implement this method and return false. The default implementation returns
true, signaling that Collect::trace must be called.source§fn trace(&self, cc: &Collection)
fn trace(&self, cc: &Collection)
Must call
Collect::trace on all held Gc pointers. If this type holds inner types that
implement Collect, a valid implementation would simply call Collect::trace on all the
held values to ensure this.Auto Trait Implementations§
impl<K, T> RefUnwindSafe for SlotMap<K, T>where K: RefUnwindSafe, T: RefUnwindSafe,
impl<K, T> Send for SlotMap<K, T>where K: Send, T: Send,
impl<K, T> Sync for SlotMap<K, T>where K: Sync, T: Sync,
impl<K, T> Unpin for SlotMap<K, T>where K: Unpin, T: Unpin,
impl<K, T> UnwindSafe for SlotMap<K, T>where K: UnwindSafe, T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more