Struct defaultmap::DefaultHashMap[][src]

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]

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.

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.

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.

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.

Trait Implementations

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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

Formats the value using the given formatter. Read more

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

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.

The returned type after indexing.

Performs 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.

Performs the mutable indexing (container[index]) operation.

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