[][src]Struct defaultmap::DefaultHashMap

pub struct DefaultHashMap<K: Eq + Hash, V: Clone> { /* fields omitted */ }

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]

pub fn new(default: V) -> DefaultHashMap<K, V>[src]

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]

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]

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]

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.

pub fn capacity(&self) -> usize[src]

pub fn reserve(&mut self, additional: usize)[src]

pub fn shrink_to_fit(&mut self)[src]

pub fn keys(&self) -> Keys<K, V>[src]

pub fn values(&self) -> Values<K, V>[src]

pub fn values_mut(&mut self) -> ValuesMut<K, V>[src]

pub fn iter(&self) -> Iter<K, V>[src]

pub fn iter_mut(&mut self) -> IterMut<K, V>[src]

pub fn entry(&mut self, key: K) -> Entry<K, V>[src]

pub fn len(&self) -> usize[src]

pub fn is_empty(&self) -> bool[src]

pub fn drain(&mut self) -> Drain<K, V>[src]

pub fn clear(&mut self)[src]

pub fn insert(&mut self, k: K, v: V) -> Option<V>[src]

pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool 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
[src]

pub fn retain<F>(&mut self, f: F) where
    F: FnMut(&K, &mut V) -> bool
[src]

Trait Implementations

impl<K: PartialEq + Eq + Hash, V: PartialEq + Clone> PartialEq<DefaultHashMap<K, V>> for DefaultHashMap<K, V>[src]

impl<K: Eq + Hash, V: Default + Clone> From<HashMap<K, V, RandomState>> for DefaultHashMap<K, V>[src]

fn from(map: HashMap<K, V>) -> DefaultHashMap<K, V>[src]

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: Clone + Eq + Hash, V: Clone + Clone> Clone for DefaultHashMap<K, V>[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<K: Eq + Hash, V: Default + Clone> Default for DefaultHashMap<K, V>[src]

fn default() -> DefaultHashMap<K, V>[src]

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 + Eq + Hash, V: Eq + Clone> Eq for DefaultHashMap<K, V>[src]

impl<K: Eq + Hash, V: Clone> Into<HashMap<K, V, RandomState>> for DefaultHashMap<K, V>[src]

fn into(self) -> HashMap<K, V>[src]

The into method can be used to convert a DefaultHashMap back into a HashMap.

impl<K: Debug + Eq + Hash, V: Debug + Clone> Debug for DefaultHashMap<K, V>[src]

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.

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.

impl<K: Eq + Hash, V: Default + Clone> FromIterator<(K, V)> for DefaultHashMap<K, V>[src]

Auto Trait Implementations

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

Blanket Implementations

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]