pub struct SmallMap<K, V>(/* private fields */);Expand description
A small map used to store a small amount of values.
The SmallMap can store up to 256 values.
let mut map = SmallMap::empty();
map.set("a", 1);
map.set("b", 2);
let Some(1) = map.set("a", 5) else { unreachable!("we know there is a one there") };
let value = map.get("b").unwrap();
assert_eq!(2, *value);
let value = map.get("a").unwrap();
assert_eq!(5, *value);Implementations§
Source§impl<K, V> SmallMap<K, V>where
K: PartialEq,
impl<K, V> SmallMap<K, V>where
K: PartialEq,
Sourcepub fn set(&mut self, key: K, value: V) -> Option<V>
pub fn set(&mut self, key: K, value: V) -> Option<V>
Set a value in the map. If there is already a value with the same key, the old value will be returned
pub fn insert_with<F>(&mut self, key: K, f: F) -> SmallIndexwhere
F: FnOnce(SmallIndex) -> V,
Sourcepub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
Get a mutable reference to a value in the map
pub fn get_index<Q>(&self, key: &Q) -> Option<SmallIndex>
pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
Sourcepub fn iter(&self) -> impl Iterator<Item = (&K, &V)> + '_
pub fn iter(&self) -> impl Iterator<Item = (&K, &V)> + '_
Iterate over the key-value pairs of the map.
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&mut K, &mut V)> + '_
Sourcepub fn get_with_index(&self, idx: SmallIndex) -> Option<&V>
pub fn get_with_index(&self, idx: SmallIndex) -> Option<&V>
Get a value ref by the value index instead of the key
Sourcepub fn get_mut_with_index(&mut self, idx: SmallIndex) -> Option<&mut V>
pub fn get_mut_with_index(&mut self, idx: SmallIndex) -> Option<&mut V>
Get a mutable value ref by the value index instead of the key
Trait Implementations§
Source§impl<K: PartialEq, V: PartialEq> PartialEq for SmallMap<K, V>
impl<K: PartialEq, V: PartialEq> PartialEq for SmallMap<K, V>
impl<K: PartialEq, V: PartialEq> StructuralPartialEq for SmallMap<K, V>
Auto Trait Implementations§
impl<K, V> Freeze for SmallMap<K, V>
impl<K, V> RefUnwindSafe for SmallMap<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for SmallMap<K, V>
impl<K, V> Sync for SmallMap<K, V>
impl<K, V> Unpin for SmallMap<K, V>
impl<K, V> UnsafeUnpin for SmallMap<K, V>
impl<K, V> UnwindSafe for SmallMap<K, V>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