SlotMap

Struct SlotMap 

Source
pub struct SlotMap<K, V> { /* private fields */ }

Implementations§

Source§

impl<V> SlotMap<SlotId, V>

Source

pub fn new(max_capacity: u32) -> Self

Source

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>

Source

pub fn with_key(max_capacity: u32) -> Self

Source

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! ⚠️
Source

pub fn capacity(&self) -> u32

Source

pub fn len(&self) -> u32

Source

pub fn is_empty(&self) -> bool

Source

pub fn collector(&self) -> &CollectorHandle

Source

pub fn pin(&self) -> Guard<'_>

Source

pub fn slots<'a>(&'a self, guard: &'a Guard<'a>) -> Slots<'a, V>

§Panics

Panics if guard.collector() does not equal self.collector().

Source§

impl<K: Key, V> SlotMap<K, V>

Source

pub fn insert<'a>(&'a self, value: V, guard: &'a Guard<'a>) -> K

§Panics

Panics if guard.collector() does not equal self.collector().

Source

pub fn insert_with_tag<'a>( &'a self, value: V, tag: u32, guard: &'a Guard<'a>, ) -> K

§Panics
  • Panics if guard.collector() does not equal self.collector().
  • Panics if tag has more than the low 8 bits set.
Source

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().

Source

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 equal self.collector().
  • Panics if tag has more than the low 8 bits set.
Source

pub fn insert_mut(&mut self, value: V) -> K

Source

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.

Source

pub fn insert_with_mut(&mut self, f: impl FnOnce(K) -> V) -> K

Source

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.

Source

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().

Source

pub fn remove_mut(&mut self, key: K) -> Option<V>

Source

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.

Source

pub fn invalidate<'a>(&'a self, key: K, guard: &'a Guard<'a>) -> Option<&'a V>

Source

pub fn remove_invalidated(&self, key: K) -> Option<()>

Source

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.

Source

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().

Source

pub fn get_mut(&mut self, key: K) -> Option<&mut V>

Source

pub fn get_disjoint_mut<const N: usize>( &mut self, keys: [K; N], ) -> Option<[&mut V; N]>

Source

pub unsafe fn get_unchecked<'a>(&'a self, key: K, guard: &'a Guard<'a>) -> &'a V

§Safety

The slot must be currently occupied.

§Panics

Panics if guard.collector() does not equal self.collector().

Source

pub unsafe fn get_unchecked_mut(&mut self, key: K) -> &mut V

§Safety

The slot must be currently occupied.

Source

pub fn iter<'a>(&'a self, guard: &'a Guard<'a>) -> Iter<'a, K, V>

§Panics

Panics if guard.collector() does not equal self.collector().

Source

pub fn iter_mut(&mut self) -> IterMut<'_, K, V>

Source§

impl<K: Key, V> SlotMap<K, MaybeUninit<V>>

Source

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().

Trait Implementations§

Source§

impl<K: Debug + Key, V: Debug> Debug for SlotMap<K, V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, K: Key, V> IntoIterator for &'a mut SlotMap<K, V>

Source§

type Item = (K, &'a mut V)

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<K, V: Send> Send for SlotMap<K, V>

Source§

impl<K, V: Send + Sync> Sync for SlotMap<K, V>

Auto Trait Implementations§

§

impl<K, V> !Freeze for SlotMap<K, V>

§

impl<K, V> RefUnwindSafe for SlotMap<K, V>
where V: RefUnwindSafe,

§

impl<K, V> Unpin for SlotMap<K, V>
where V: Unpin,

§

impl<K, V> UnwindSafe for SlotMap<K, V>
where V: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.