pub struct OrderedMap<V> { /* private fields */ }Expand description
A map from strings to V that keeps its keys in the order they were
inserted. Lookups are O(1): small maps scan their few entries, and larger
ones keep a hash index of positions. Inserting or removing at a position
shifts the entries after it, in O(n).
Two maps are equal when they have the same keys with equal values, in any order.
Implementations§
Source§impl<V> OrderedMap<V>
impl<V> OrderedMap<V>
pub fn new() -> Self
pub fn with_capacity(capacity: usize) -> Self
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn get(&self, key: &str) -> Option<&V>
pub fn get_mut(&mut self, key: &str) -> Option<&mut V>
pub fn contains_key(&self, key: &str) -> bool
Sourcepub fn insert(&mut self, key: impl Into<String>, value: V) -> Option<V>
pub fn insert(&mut self, key: impl Into<String>, value: V) -> Option<V>
Sets key to value, returning the value it replaced. A new key goes
last; an existing one keeps its place.
Sourcepub fn insert_at(&mut self, at: usize, key: impl Into<String>, value: V)
pub fn insert_at(&mut self, at: usize, key: impl Into<String>, value: V)
Inserts key, which must not be present yet, at position at,
shifting the entries after it.
Sourcepub fn remove_full(&mut self, key: &str) -> Option<(usize, V)>
pub fn remove_full(&mut self, key: &str) -> Option<(usize, V)>
Removes key, returning its position and value. The other keys keep
their order.
Sourcepub fn remove(&mut self, key: &str) -> Option<V>
pub fn remove(&mut self, key: &str) -> Option<V>
Removes key, returning its value. The other keys keep their order.
Sourcepub fn iter_mut(&mut self) -> impl ExactSizeIterator<Item = (&String, &mut V)>
pub fn iter_mut(&mut self) -> impl ExactSizeIterator<Item = (&String, &mut V)>
The entries, in order, with mutable values.
pub fn keys( &self, ) -> impl DoubleEndedIterator<Item = &String> + ExactSizeIterator + Clone
pub fn values( &self, ) -> impl DoubleEndedIterator<Item = &V> + ExactSizeIterator + Clone
pub fn values_mut(&mut self) -> impl ExactSizeIterator<Item = &mut V>
Trait Implementations§
Source§impl<V: Clone> Clone for OrderedMap<V>
impl<V: Clone> Clone for OrderedMap<V>
Source§impl<V: Debug> Debug for OrderedMap<V>
impl<V: Debug> Debug for OrderedMap<V>
Source§impl<V> Default for OrderedMap<V>
impl<V> Default for OrderedMap<V>
Source§impl<K: Into<String>, V> FromIterator<(K, V)> for OrderedMap<V>
impl<K: Into<String>, V> FromIterator<(K, V)> for OrderedMap<V>
Source§fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self
A key that repeats keeps its first place and its last value.