Struct defaultmap::DefaultHashMap
[−]
[src]
pub struct DefaultHashMap<K: Eq + Hash, V: Clone> { /* fields omitted */ }
A HashMap
that has returns a default when keys are accessed that are not present.
Methods
impl<K: Eq + Hash, V: Clone> DefaultHashMap<K, V>
[src]
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.
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.
fn get<Q: ?Sized, QB: Borrow<Q>>(&self, key: QB) -> &V where
K: Borrow<Q>,
Q: Hash + Eq,
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.
fn get_mut(&mut self, key: K) -> &mut V
Returns 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]
These methods simply forward to the underlying HashMap
, see that
documentation for
the usage of these methods.
fn capacity(&self) -> usize
fn reserve(&mut self, additional: usize)
fn shrink_to_fit(&mut self)
fn keys(&self) -> Keys<K, V>
fn values(&self) -> Values<K, V>
fn values_mut(&mut self) -> ValuesMut<K, V>
fn iter(&self) -> Iter<K, V>
fn iter_mut(&mut self) -> IterMut<K, V>
fn entry(&mut self, key: K) -> Entry<K, V>
fn len(&self) -> usize
fn is_empty(&self) -> bool
fn drain(&mut self) -> Drain<K, V>
fn clear(&mut self)
fn insert(&mut self, k: K, v: V) -> Option<V>
fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool where
K: Borrow<Q>,
Q: Hash + Eq,
K: Borrow<Q>,
Q: Hash + Eq,
fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V> where
K: Borrow<Q>,
Q: Hash + Eq,
K: Borrow<Q>,
Q: Hash + Eq,
fn retain<F>(&mut self, f: F) where
F: FnMut(&K, &mut V) -> bool,
F: FnMut(&K, &mut V) -> bool,
Trait Implementations
impl<K: PartialEq + Eq + Hash, V: PartialEq + Clone> PartialEq for DefaultHashMap<K, V>
[src]
fn eq(&self, __arg_0: &DefaultHashMap<K, V>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &DefaultHashMap<K, V>) -> bool
This method tests for !=
.
impl<K: Eq + Eq + Hash, V: Eq + Clone> Eq for DefaultHashMap<K, V>
[src]
impl<K: Debug + Eq + Hash, V: Debug + Clone> Debug for DefaultHashMap<K, V>
[src]
impl<K: Eq + Hash, V: Default + Clone> Default for 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]
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]
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]
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
The method for the indexing (container[index]
) operation
impl<K: Eq + Hash, V: Clone> IndexMut<K> for DefaultHashMap<K, V>
[src]
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.
fn index_mut(&mut self, index: K) -> &mut V
The method for the mutable indexing (container[index]
) operation