Struct defaultmap::DefaultHashMap [−][src]
A HashMap that returns a default when keys are accessed that are not present.
Methods
impl<K: Eq + Hash, V: Clone> DefaultHashMap<K, V>[src]
impl<K: Eq + Hash, V: Clone> DefaultHashMap<K, V>pub fn new(default: V) -> DefaultHashMap<K, V>[src]
pub fn new(default: V) -> DefaultHashMap<K, V>Creates an empty DefaultHashmap with default as the default for missing keys.
When the provided default is equivalent to V::default() it is preferred to use
DefaultHashMap::default() instead.
pub fn new_with_map(default: V, map: HashMap<K, V>) -> DefaultHashMap<K, V>[src]
pub fn new_with_map(default: V, map: HashMap<K, V>) -> DefaultHashMap<K, V>Creates a DefaultHashMap based on a default and an already existing HashMap.
If V::default() is the supplied default, usage of the from() constructor or the
into() method on the original HashMap is preferred.
pub fn get<Q: ?Sized, QB: Borrow<Q>>(&self, key: QB) -> &V where
K: Borrow<Q>,
Q: Hash + Eq, [src]
pub fn get<Q: ?Sized, QB: Borrow<Q>>(&self, key: QB) -> &V where
K: Borrow<Q>,
Q: Hash + Eq, Returns a reference to the value stored for the provided key.
If the key is not in the DefaultHashMap a reference to the default value is returned.
Usually the map[key] method of retrieving keys is prefered over using get directly.
This method accepts both references and owned values as the key.
pub fn get_mut(&mut self, key: K) -> &mut V[src]
pub fn get_mut(&mut self, key: K) -> &mut VReturns a mutable reference to the value stored for the provided key.
If there is no value stored for the key the default value is first inserted for this
key before returning the reference.
Usually the map[key] = new_val is prefered over using get_mut directly.
This method only accepts owned values as the key.
impl<K: Eq + Hash, V: Clone> DefaultHashMap<K, V>[src]
impl<K: Eq + Hash, V: Clone> DefaultHashMap<K, V>These methods simply forward to the underlying HashMap, see that
documentation for
the usage of these methods.
pub fn capacity(&self) -> usize[src]
pub fn capacity(&self) -> usizepub fn reserve(&mut self, additional: usize)[src]
pub fn reserve(&mut self, additional: usize)pub fn shrink_to_fit(&mut self)[src]
pub fn shrink_to_fit(&mut self)pub fn keys(&self) -> Keys<K, V>[src]
pub fn keys(&self) -> Keys<K, V>pub fn values(&self) -> Values<K, V>[src]
pub fn values(&self) -> Values<K, V>pub fn values_mut(&mut self) -> ValuesMut<K, V>[src]
pub fn values_mut(&mut self) -> ValuesMut<K, V>pub fn iter(&self) -> Iter<K, V>[src]
pub fn iter(&self) -> Iter<K, V>pub fn iter_mut(&mut self) -> IterMut<K, V>[src]
pub fn iter_mut(&mut self) -> IterMut<K, V>pub fn entry(&mut self, key: K) -> Entry<K, V>[src]
pub fn entry(&mut self, key: K) -> Entry<K, V>pub fn len(&self) -> usize[src]
pub fn len(&self) -> usizepub fn is_empty(&self) -> bool[src]
pub fn is_empty(&self) -> boolpub fn drain(&mut self) -> Drain<K, V>[src]
pub fn drain(&mut self) -> Drain<K, V>pub fn clear(&mut self)[src]
pub fn clear(&mut self)pub fn insert(&mut self, k: K, v: V) -> Option<V>[src]
pub fn insert(&mut self, k: K, v: V) -> Option<V>pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool where
K: Borrow<Q>,
Q: Hash + Eq, [src]
pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool where
K: Borrow<Q>,
Q: Hash + Eq, pub fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V> where
K: Borrow<Q>,
Q: Hash + Eq, [src]
pub fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V> where
K: Borrow<Q>,
Q: Hash + Eq, pub fn retain<F>(&mut self, f: F) where
F: FnMut(&K, &mut V) -> bool, [src]
pub fn retain<F>(&mut self, f: F) where
F: FnMut(&K, &mut V) -> bool, Trait Implementations
impl<K: PartialEq + Eq + Hash, V: PartialEq + Clone> PartialEq for DefaultHashMap<K, V>[src]
impl<K: PartialEq + Eq + Hash, V: PartialEq + Clone> PartialEq for DefaultHashMap<K, V>fn eq(&self, other: &DefaultHashMap<K, V>) -> bool[src]
fn eq(&self, other: &DefaultHashMap<K, V>) -> boolThis method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &DefaultHashMap<K, V>) -> bool[src]
fn ne(&self, other: &DefaultHashMap<K, V>) -> boolThis method tests for !=.
impl<K: Eq + Eq + Hash, V: Eq + Clone> Eq for DefaultHashMap<K, V>[src]
impl<K: Eq + Eq + Hash, V: Eq + Clone> Eq for DefaultHashMap<K, V>impl<K: Clone + Eq + Hash, V: Clone + Clone> Clone for DefaultHashMap<K, V>[src]
impl<K: Clone + Eq + Hash, V: Clone + Clone> Clone for DefaultHashMap<K, V>fn clone(&self) -> DefaultHashMap<K, V>[src]
fn clone(&self) -> DefaultHashMap<K, V>Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
fn clone_from(&mut self, source: &Self)Performs copy-assignment from source. Read more
impl<K: Debug + Eq + Hash, V: Debug + Clone> Debug for DefaultHashMap<K, V>[src]
impl<K: Debug + Eq + Hash, V: Debug + Clone> Debug for DefaultHashMap<K, V>fn fmt(&self, f: &mut Formatter) -> Result[src]
fn fmt(&self, f: &mut Formatter) -> ResultFormats the value using the given formatter. Read more
impl<K: Eq + Hash, V: Default + Clone> Default for DefaultHashMap<K, V>[src]
impl<K: Eq + Hash, V: Default + Clone> Default for DefaultHashMap<K, V>fn default() -> DefaultHashMap<K, V>[src]
fn default() -> DefaultHashMap<K, V>The default() constructor creates an empty DefaultHashMap with the default of V
as the default for missing keys.
This is desired default for most use cases, if your case requires a
different default you should use the new() constructor.
impl<K: Eq + Hash, V: Default + Clone> From<HashMap<K, V>> for DefaultHashMap<K, V>[src]
impl<K: Eq + Hash, V: Default + Clone> From<HashMap<K, V>> for DefaultHashMap<K, V>fn from(map: HashMap<K, V>) -> DefaultHashMap<K, V>[src]
fn from(map: HashMap<K, V>) -> DefaultHashMap<K, V>If you already have a HashMap that you would like to convert to a
DefaultHashMap you can use the into() method on the HashMap or the
from() constructor of DefaultHashMap.
The default value for missing keys will be V::default(),
if this is not desired DefaultHashMap::new_with_map() should be used.
impl<K: Eq + Hash, V: Clone> Into<HashMap<K, V>> for DefaultHashMap<K, V>[src]
impl<K: Eq + Hash, V: Clone> Into<HashMap<K, V>> for DefaultHashMap<K, V>fn into(self) -> HashMap<K, V>[src]
fn into(self) -> HashMap<K, V>The into method can be used to convert a DefaultHashMap back into a
HashMap.
impl<'a, K: Eq + Hash, KB: Borrow<K>, V: Clone> Index<KB> for DefaultHashMap<K, V>[src]
impl<'a, K: Eq + Hash, KB: Borrow<K>, V: Clone> Index<KB> for DefaultHashMap<K, V>Implements the Index trait so you can do map[key].
Nonmutable indexing can be done both by passing a reference or an owned value as the key.
type Output = V
The returned type after indexing.
fn index(&self, index: KB) -> &V[src]
fn index(&self, index: KB) -> &VPerforms the indexing (container[index]) operation.
impl<K: Eq + Hash, V: Clone> IndexMut<K> for DefaultHashMap<K, V>[src]
impl<K: Eq + Hash, V: Clone> IndexMut<K> for DefaultHashMap<K, V>Implements the IndexMut trait so you can do map[key] = val.
Mutably indexing can only be done when passing an owned value as the key.
Auto Trait Implementations
impl<K, V> Send for DefaultHashMap<K, V> where
K: Send,
V: Send,
impl<K, V> Send for DefaultHashMap<K, V> where
K: Send,
V: Send, impl<K, V> Sync for DefaultHashMap<K, V> where
K: Sync,
V: Sync,
impl<K, V> Sync for DefaultHashMap<K, V> where
K: Sync,
V: Sync,