Struct 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>

Source

pub fn new() -> Self

Creates a new empty container.

Source

pub fn insert(&mut self, value: T) -> K

Adds a new value to the map and returns a new key that references it.

Source

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.

Source

pub fn clear(&mut self)

Removes all values from the slotmap.

Source

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.

Source

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

Get a reference to a value in the map.

Source

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

Get a mutable reference to a value in the map.

Source

pub fn len(&self) -> usize

Get the number of values stored in the map.

Source

pub fn is_empty(&self) -> bool

Checks if the map is currently empty.

Source

pub fn iter(&self) -> Iter<'_, K, T>

Iterates over the keys and values currently stored in the map.

Source

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

Mutably iterates over the keys and values currently stored in the map.

Trait Implementations§

Source§

impl<K: Clone + Key, T: Clone> Clone for SlotMap<K, T>

Source§

fn clone(&self) -> SlotMap<K, T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

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

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)

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.
Source§

impl<K: Key, T> Default for SlotMap<K, T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<K: Key, T> IntoIterator for SlotMap<K, T>

Source§

type IntoIter = IntoIter<K, T>

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

type Item = (K, T)

The type of the elements being iterated over.
Source§

fn into_iter(self) -> IntoIter<K, T>

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<K, T> Freeze for SlotMap<K, T>

§

impl<K, T> RefUnwindSafe for SlotMap<K, T>

§

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,