pub struct SlotMap<K, V> { /* private fields */ }Implementations§
Source§impl<V> SlotMap<SlotId, V>
impl<V> SlotMap<SlotId, V>
pub fn new(max_capacity: u32) -> Self
Sourcepub unsafe fn with_collector(
max_capacity: u32,
collector: CollectorHandle,
) -> Self
pub unsafe fn with_collector( max_capacity: u32, collector: CollectorHandle, ) -> Self
§Safety
Please see the safety documentation of with_collector_and_key.
Source§impl<K, V> SlotMap<K, V>
impl<K, V> SlotMap<K, V>
pub fn with_key(max_capacity: u32) -> Self
Sourcepub unsafe fn with_collector_and_key(
max_capacity: u32,
collector: CollectorHandle,
) -> Self
pub unsafe fn with_collector_and_key( max_capacity: u32, collector: CollectorHandle, ) -> Self
§Safety
The given collector must not be used to create any Guard that outlives the collection.
It would result in the Guard’s drop implementation attempting to free slots from the
already freed collection, resulting in a Use-After-Free. You must ensure that the Guard
has its lifetime bound to the collections it protects.
Note that it is not enough for CollectorHandle::pin to be unsafe because
SlotMap::pin is safe:
let collector = CollectorHandle::new();
let map1 = unsafe { SlotMap::<_, i32>::with_collector(1, collector.clone()) };
let guard = &map1.pin();
let map2 = unsafe { SlotMap::<_, i32>::with_collector(1, collector) };
map2.remove(map2.insert(69, guard), guard);
// undefined behavior! ⚠️pub fn capacity(&self) -> u32
pub fn len(&self) -> u32
pub fn is_empty(&self) -> bool
pub fn collector(&self) -> &CollectorHandle
pub fn pin(&self) -> Guard<'_>
Source§impl<K: Key, V> SlotMap<K, V>
impl<K: Key, V> SlotMap<K, V>
Sourcepub fn insert<'a>(&'a self, value: V, guard: &'a Guard<'a>) -> K
pub fn insert<'a>(&'a self, value: V, guard: &'a Guard<'a>) -> K
§Panics
Panics if guard.collector() does not equal self.collector().
Sourcepub fn insert_with_tag<'a>(
&'a self,
value: V,
tag: u32,
guard: &'a Guard<'a>,
) -> K
pub fn insert_with_tag<'a>( &'a self, value: V, tag: u32, guard: &'a Guard<'a>, ) -> K
§Panics
- Panics if
guard.collector()does not equalself.collector(). - Panics if
taghas more than the low 8 bits set.
Sourcepub fn insert_with<'a>(
&'a self,
guard: &'a Guard<'a>,
f: impl FnOnce(K) -> V,
) -> K
pub fn insert_with<'a>( &'a self, guard: &'a Guard<'a>, f: impl FnOnce(K) -> V, ) -> K
§Panics
Panics if guard.global() is Some and does not equal self.global().
Sourcepub fn insert_with_tag_with<'a>(
&'a self,
tag: u32,
guard: &'a Guard<'a>,
f: impl FnOnce(K) -> V,
) -> K
pub fn insert_with_tag_with<'a>( &'a self, tag: u32, guard: &'a Guard<'a>, f: impl FnOnce(K) -> V, ) -> K
§Panics
- Panics if
guard.collector()does not equalself.collector(). - Panics if
taghas more than the low 8 bits set.
pub fn insert_mut(&mut self, value: V) -> K
Sourcepub fn insert_with_tag_mut(&mut self, value: V, tag: u32) -> K
pub fn insert_with_tag_mut(&mut self, value: V, tag: u32) -> K
§Panics
Panics if tag has more than the low 8 bits set.
pub fn insert_with_mut(&mut self, f: impl FnOnce(K) -> V) -> K
Sourcepub fn insert_with_tag_with_mut(
&mut self,
tag: u32,
f: impl FnOnce(K) -> V,
) -> K
pub fn insert_with_tag_with_mut( &mut self, tag: u32, f: impl FnOnce(K) -> V, ) -> K
§Panics
Panics if tag has more than the low 8 bits set.
Sourcepub fn remove<'a>(&'a self, key: K, guard: &'a Guard<'a>) -> Option<&'a V>
pub fn remove<'a>(&'a self, key: K, guard: &'a Guard<'a>) -> Option<&'a V>
§Panics
Panics if guard.collector() does not equal self.collector().
pub fn remove_mut(&mut self, key: K) -> Option<V>
Sourcepub unsafe fn remove_unchecked<'a>(
&'a self,
key: K,
guard: &'a Guard<'a>,
) -> &'a V
pub unsafe fn remove_unchecked<'a>( &'a self, key: K, guard: &'a Guard<'a>, ) -> &'a V
§Safety
key must refer to a currently occupied slot. That also excludes a race condition when
calling this method.
pub fn invalidate<'a>(&'a self, key: K, guard: &'a Guard<'a>) -> Option<&'a V>
pub fn remove_invalidated(&self, key: K) -> Option<()>
Sourcepub unsafe fn remove_invalidated_unchecked(&self, key: K)
pub unsafe fn remove_invalidated_unchecked(&self, key: K)
§Safety
key must refer to a currently invalidated slot. That also excludes a race condition when
calling this method.
Sourcepub fn get<'a>(&'a self, key: K, guard: &'a Guard<'a>) -> Option<&'a V>
pub fn get<'a>(&'a self, key: K, guard: &'a Guard<'a>) -> Option<&'a V>
§Panics
Panics if guard.collector() does not equal self.collector().
pub fn get_mut(&mut self, key: K) -> Option<&mut V>
pub fn get_disjoint_mut<const N: usize>( &mut self, keys: [K; N], ) -> Option<[&mut V; N]>
Sourcepub unsafe fn get_unchecked<'a>(&'a self, key: K, guard: &'a Guard<'a>) -> &'a V
pub unsafe fn get_unchecked<'a>(&'a self, key: K, guard: &'a Guard<'a>) -> &'a V
Sourcepub unsafe fn get_unchecked_mut(&mut self, key: K) -> &mut V
pub unsafe fn get_unchecked_mut(&mut self, key: K) -> &mut V
§Safety
The slot must be currently occupied.
Sourcepub fn iter<'a>(&'a self, guard: &'a Guard<'a>) -> Iter<'a, K, V> ⓘ
pub fn iter<'a>(&'a self, guard: &'a Guard<'a>) -> Iter<'a, K, V> ⓘ
§Panics
Panics if guard.collector() does not equal self.collector().
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
Source§impl<K: Key, V> SlotMap<K, MaybeUninit<V>>
impl<K: Key, V> SlotMap<K, MaybeUninit<V>>
Sourcepub fn revive_or_insert_with<'a>(
&'a self,
guard: &'a Guard<'a>,
f: impl FnOnce(K) -> MaybeUninit<V>,
) -> (K, &'a MaybeUninit<V>)
pub fn revive_or_insert_with<'a>( &'a self, guard: &'a Guard<'a>, f: impl FnOnce(K) -> MaybeUninit<V>, ) -> (K, &'a MaybeUninit<V>)
§Panics
Panics if guard.collector() does not equal self.collector().