pub struct ChainMap<K, V, S = RandomState> { /* private fields */ }Expand description
The ChainMap type. See the module level documentation for
more.
Implementations§
Source§impl<K, V, S> ChainMap<K, V, S>
impl<K, V, S> ChainMap<K, V, S>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Sourcepub fn push_map(&mut self, map: HashMap<K, V, S>)
pub fn push_map(&mut self, map: HashMap<K, V, S>)
Appends a map to the lowest-precedence end of the chain
§Panics
Panics if the number of maps in the chain overflows a usize.
§Examples
use std::collections::HashMap;
use chain_map::ChainMap;
let mut hash = HashMap::new();
hash.insert("key", "value");
let mut chain = ChainMap::new();
chain.push_map(hash);Source§impl<K, V, S> ChainMap<K, V, S>
impl<K, V, S> ChainMap<K, V, S>
Sourcepub fn contains_key<Q>(&self, k: &Q) -> bool
pub fn contains_key<Q>(&self, k: &Q) -> bool
Returns true if the ChainMap contains a value for the given key.
As with HashMap::contains_key, the supplied key may be any borrowed
form of the key type, but Hash and Eq on the borrowed form must
match those for the key type.
§Examples
use std::collections::HashMap;
use chain_map::ChainMap;
let mut hash = HashMap::new();
hash.insert("key", "value");
let mut chain = ChainMap::new();
chain.push_map(hash);
assert!(chain.contains_key("key"));Sourcepub fn get<Q>(&self, k: &Q) -> Option<&V>
pub fn get<Q>(&self, k: &Q) -> Option<&V>
Returns the highest-precedence value associated with the given key.
As with HashMap::get, the supplied key may be any borrowed form of
the key type, but Hash and Eq on the borrowed form must match
those for the key type.
§Examples
use std::collections::HashMap;
use chain_map::ChainMap;
let mut hash = HashMap::new();
hash.insert("key", "value");
let mut chain = ChainMap::new();
chain.push_map(hash);
assert_eq!(chain.get("key"), Some(&"value"));Trait Implementations§
Source§impl<K, V, S> Extend<HashMap<K, V, S>> for ChainMap<K, V, S>
impl<K, V, S> Extend<HashMap<K, V, S>> for ChainMap<K, V, S>
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = HashMap<K, V, S>>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = HashMap<K, V, S>>,
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<K, V, S> FromIterator<HashMap<K, V, S>> for ChainMap<K, V, S>
impl<K, V, S> FromIterator<HashMap<K, V, S>> for ChainMap<K, V, S>
impl<K, V, S> Eq for ChainMap<K, V, S>
Auto Trait Implementations§
impl<K, V, S> Freeze for ChainMap<K, V, S>
impl<K, V, S> RefUnwindSafe for ChainMap<K, V, S>
impl<K, V, S> Send for ChainMap<K, V, S>
impl<K, V, S> Sync for ChainMap<K, V, S>
impl<K, V, S> Unpin for ChainMap<K, V, S>
impl<K, V, S> UnwindSafe for ChainMap<K, V, S>
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