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 retain_mut<F: FnMut(K, &mut T) -> bool>(&mut self, f: F)
pub fn retain_mut<F: FnMut(K, &mut T) -> bool>(&mut self, f: F)
Retains only the values for which the predicate returns true. For all retained values, any existing keys are still valid after this operation.
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>
impl<K: Key, T> Collect for SlotMap<K, T>
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> Freeze for SlotMap<K, T>
impl<K, T> RefUnwindSafe for SlotMap<K, T>where
K: RefUnwindSafe,
T: RefUnwindSafe,
impl<K, T> Send for SlotMap<K, T>
impl<K, T> Sync for SlotMap<K, T>
impl<K, T> Unpin for SlotMap<K, T>
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