pub struct OrdinalArrayMap<K, V, const S: usize> { /* private fields */ }Expand description
Map backed by an array, allocated on the stack.
Due to Rust limitations, the array size must be provided as a type parameter.
§Example
use ordinal_map::map::OrdinalArrayMap;
use ordinal_map::Ordinal;
#[derive(Ordinal)]
enum Weather {
Sunny,
Rainy,
Snowy,
}
let mut map = OrdinalArrayMap::<_, _, { Weather::ORDINAL_SIZE }>::new();
map.insert(Weather::Sunny, "good");
map.insert(Weather::Rainy, "it depends");This map is sparse (not every key has an associated value).
For a total map, see OrdinalTotalMap
and OrdinalTotalArrayMap.
Implementations§
Source§impl<K: Ordinal, V, const S: usize> OrdinalArrayMap<K, V, S>
impl<K: Ordinal, V, const S: usize> OrdinalArrayMap<K, V, S>
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
The number of elements in the map.
This operation is O(K::ORDINAL_SIZE).
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Check if the map contains a key.
Sourcepub fn insert(&mut self, key: K, value: V) -> Option<V>
pub fn insert(&mut self, key: K, value: V) -> Option<V>
Insert a value into the map, returning the previous value if it existed.
Sourcepub fn remove(&mut self, key: &K) -> Option<V>
pub fn remove(&mut self, key: &K) -> Option<V>
Remove a value from the map, returning it if it existed.
Sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V>
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V>
Iterate over the values of the map mutably.
Trait Implementations§
Source§impl<K: Ordinal, V, const S: usize> FromIterator<(K, V)> for OrdinalArrayMap<K, V, S>
impl<K: Ordinal, V, const S: usize> FromIterator<(K, V)> for OrdinalArrayMap<K, V, S>
Source§impl<K: Ordinal, V, const S: usize> IntoIterator for OrdinalArrayMap<K, V, S>
impl<K: Ordinal, V, const S: usize> IntoIterator for OrdinalArrayMap<K, V, S>
Source§impl<'a, K: Ordinal, V, const S: usize> IntoIterator for &'a OrdinalArrayMap<K, V, S>
impl<'a, K: Ordinal, V, const S: usize> IntoIterator for &'a OrdinalArrayMap<K, V, S>
Auto Trait Implementations§
impl<K, V, const S: usize> Freeze for OrdinalArrayMap<K, V, S>where
V: Freeze,
impl<K, V, const S: usize> RefUnwindSafe for OrdinalArrayMap<K, V, S>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V, const S: usize> Send for OrdinalArrayMap<K, V, S>
impl<K, V, const S: usize> Sync for OrdinalArrayMap<K, V, S>
impl<K, V, const S: usize> Unpin for OrdinalArrayMap<K, V, S>
impl<K, V, const S: usize> UnsafeUnpin for OrdinalArrayMap<K, V, S>where
V: UnsafeUnpin,
impl<K, V, const S: usize> UnwindSafe for OrdinalArrayMap<K, V, S>where
K: UnwindSafe,
V: 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