pub trait LinearMap<K: Eq, V: Sized + PartialEq>: AsMutSlice<K, V> {
type Backing;
// Required methods
fn as_slice(&self) -> &[(K, V)];
fn into_inner(self) -> Self::Backing;
// Provided methods
fn contains_key(&self, key: &K) -> bool { ... }
fn contains_value(&self, value: &V) -> bool { ... }
fn get<'a>(&'a self, key: &'a K) -> Option<&'a V> { ... }
fn get_mut<'a>(&'a mut self, key: &'a K) -> Option<&'a mut V> { ... }
fn nth_value<'a>(&'a self, index: usize) -> Option<&'a V>
where K: 'a { ... }
fn nth_value_mut<'a>(&'a mut self, index: usize) -> Option<&'a mut V>
where K: 'a { ... }
fn nth_key<'a>(&'a self, index: usize) -> Option<&'a K>
where V: 'a { ... }
fn nth_key_mut<'a>(&'a mut self, index: usize) -> Option<&'a mut K>
where V: 'a { ... }
fn replace(&mut self, key: &K, value: V) { ... }
fn merge_from_iter<'a>(&'a mut self, iter: impl Iterator<Item = &'a (K, V)>)
where K: 'a,
V: 'a + Clone { ... }
}Expand description
Provides methods for maps backed by linear data structures like arrays and vecs. Because arrays may implement this type, we cannot assume that implementors will be dynamically sized. Only methods which do not require manipulating the length or capacity of the store are provided here: this is to permit the implementation of fixed sized sets backed by arrays.
Required Associated Types§
Required Methods§
Sourcefn into_inner(self) -> Self::Backing
fn into_inner(self) -> Self::Backing
Consumes self, returning the underlying store.
Provided Methods§
Sourcefn contains_key(&self, key: &K) -> bool
fn contains_key(&self, key: &K) -> bool
Returns true if this map contains the given key. False otherwise.
Sourcefn contains_value(&self, value: &V) -> bool
fn contains_value(&self, value: &V) -> bool
Returns true if this map contains a given value. False otherwise.
Sourcefn get<'a>(&'a self, key: &'a K) -> Option<&'a V>
fn get<'a>(&'a self, key: &'a K) -> Option<&'a V>
Gets a reference with the associated key. Will return None if that i key is not in the map.
Sourcefn get_mut<'a>(&'a mut self, key: &'a K) -> Option<&'a mut V>
fn get_mut<'a>(&'a mut self, key: &'a K) -> Option<&'a mut V>
Gets a mutable reference with the associated key. Will return None if that key is not in the map.
Sourcefn nth_value<'a>(&'a self, index: usize) -> Option<&'a V>where
K: 'a,
fn nth_value<'a>(&'a self, index: usize) -> Option<&'a V>where
K: 'a,
Gets a reference to the nth value in the map. Will return None if index is out of bounds.
Sourcefn nth_value_mut<'a>(&'a mut self, index: usize) -> Option<&'a mut V>where
K: 'a,
fn nth_value_mut<'a>(&'a mut self, index: usize) -> Option<&'a mut V>where
K: 'a,
Gets a reference to the nth value in the map. Will return None if index is out of bounds.
Sourcefn nth_key<'a>(&'a self, index: usize) -> Option<&'a K>where
V: 'a,
fn nth_key<'a>(&'a self, index: usize) -> Option<&'a K>where
V: 'a,
Gets a reference to the nth value in the map. Will return None if index is out of bounds.
Sourcefn nth_key_mut<'a>(&'a mut self, index: usize) -> Option<&'a mut K>where
V: 'a,
fn nth_key_mut<'a>(&'a mut self, index: usize) -> Option<&'a mut K>where
V: 'a,
Gets a reference to the nth key in the map. Will return None if index is out of bounds.
Sourcefn replace(&mut self, key: &K, value: V)
fn replace(&mut self, key: &K, value: V)
Searches for a key == key in the map. If it is present replaces its value with “value”. If not, it does nothing.
Sourcefn merge_from_iter<'a>(&'a mut self, iter: impl Iterator<Item = &'a (K, V)>)where
K: 'a,
V: 'a + Clone,
fn merge_from_iter<'a>(&'a mut self, iter: impl Iterator<Item = &'a (K, V)>)where
K: 'a,
V: 'a + Clone,
For every key in iter which matches a key in self, this method replaces the value from iter in self, “merging” the iterator and the map.
for example: [(A,1), (B, 2)].merge([(A,1), (B, 2’), (C, 2), (D, 3)].into_iter()) will yield a map: [(A, 1), (B, 2’)]
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.