pub struct EnumMap<K: EnumId, V> { /* private fields */ }Expand description
A map from an EnumId key to values,
implemented using an inline array.
This is similar to a EnumMap and is also “direct”,
although that is omitted from the name for conciseness.
Implementing the EnumId trait implies that the ids are relatively compact,
although this is not a strict requirement.
There is no entry API because the overhead of lookups is very small.
Implementations§
Source§impl<K: EnumId, V> EnumMap<K, V>
impl<K: EnumId, V> EnumMap<K, V>
Sourcepub fn new_boxed() -> Box<Self>
pub fn new_boxed() -> Box<Self>
Create a new map with no entries, allocating memory on the heap instead of the stack.
Using Box::new(EnumMapDirect::new()) could require moving the underlying table
from the stack to the heap, as LLVM can struggle at eliminating copies.
This method avoids that copy by always allocating in-place.
Sourcepub fn contains_key(&self, id: impl EquivalentId<K>) -> bool
pub fn contains_key(&self, id: impl EquivalentId<K>) -> bool
Check if the specified key is present in the map.
Sourcepub fn get(&self, id: impl EquivalentId<K>) -> Option<&V>
pub fn get(&self, id: impl EquivalentId<K>) -> Option<&V>
Get the value associated with the specified key, or None if missing.
Sourcepub fn get_mut(&mut self, id: impl EquivalentId<K>) -> Option<&mut V>
pub fn get_mut(&mut self, id: impl EquivalentId<K>) -> Option<&mut V>
Get a mutable reference to the value associated with the specified key,
or None if missing.
Sourcepub fn insert(&mut self, id: K, value: V) -> Option<V>
pub fn insert(&mut self, id: K, value: V) -> Option<V>
Insert a key and a value, returning the previous value.
Sourcepub fn remove(&mut self, id: impl EquivalentId<K>) -> Option<V>
pub fn remove(&mut self, id: impl EquivalentId<K>) -> Option<V>
Remove a value associated with the given, returning the previous value ifp resent.
Sourcepub fn iter(&self) -> Iter<'_, K, V> ⓘ
pub fn iter(&self) -> Iter<'_, K, V> ⓘ
Iterate over the key-value pairs in the map.
Guaranteed to be sorted by the integer id of the key.
Trait Implementations§
Source§impl<'de, K, V> Deserialize<'de> for EnumMap<K, V>
impl<'de, K, V> Deserialize<'de> for EnumMap<K, V>
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl<'a, K: EnumId, V: Clone> Extend<(K, &'a V)> for EnumMap<K, V>
impl<'a, K: EnumId, V: Clone> Extend<(K, &'a V)> for EnumMap<K, V>
Source§fn extend<T: IntoIterator<Item = (K, &'a V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (K, &'a V)>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<K: EnumId, V> Extend<(K, V)> for EnumMap<K, V>
impl<K: EnumId, V> Extend<(K, V)> for EnumMap<K, V>
Source§fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<'a, K: EnumId, V> IntoIterator for &'a EnumMap<K, V>
impl<'a, K: EnumId, V> IntoIterator for &'a EnumMap<K, V>
Source§impl<'a, K: EnumId, V> IntoIterator for &'a mut EnumMap<K, V>
impl<'a, K: EnumId, V> IntoIterator for &'a mut EnumMap<K, V>
Source§impl<K: EnumId, V> IntoIterator for EnumMap<K, V>
impl<K: EnumId, V> IntoIterator for EnumMap<K, V>
impl<K: EnumId, V: Eq> Eq for EnumMap<K, V>
Auto Trait Implementations§
impl<K, V> Freeze for EnumMap<K, V>
impl<K, V> RefUnwindSafe for EnumMap<K, V>
impl<K, V> Send for EnumMap<K, V>
impl<K, V> Sync for EnumMap<K, V>
impl<K, V> Unpin for EnumMap<K, V>
impl<K, V> UnwindSafe for EnumMap<K, V>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.