[][src]Trait hashmap_entry_ownable::EntryAPI

pub trait EntryAPI<K, Q: ?Sized, V, S> where
    K: Borrow<Q>,
    Q: ToOwned<Owned = K>, 
{ fn entry_ownable<'a, 'q>(
        &'a mut self,
        key: &'q Q
    ) -> Entry<'a, 'q, K, Q, V, S>; }

Required methods

fn entry_ownable<'a, 'q>(&'a mut self, key: &'q Q) -> Entry<'a, 'q, K, Q, V, S>

Gets the given key's corresponding entry in the map for in-place manipulation, creating copy of the key if necessary.

The key may be any borrowed form of the map's key type, but Hash and Eq on the borrowed form must match those for the key type.

Examples

use std::collections::HashMap;
use hashmap_entry_ownable::EntryAPI;

let mut words: HashMap<String, _> = HashMap::new();

let rhyme = vec![
    "Mary", "had", "a", "little", "lamb",
    "little", "lamb", "little", "lamb",
];

for w in rhyme {
    let counter = words.entry_ownable(w).or_insert(0);
    *counter += 1;
}

assert_eq!(words["Mary"], 1);
assert_eq!(words["lamb"], 3);
assert_eq!(words.get("fleece"), None);
Loading content...

Implementations on Foreign Types

impl<K, Q: ?Sized, V, S> EntryAPI<K, Q, V, S> for HashMap<K, V, S> where
    K: Borrow<Q> + Hash + Eq,
    Q: ToOwned<Owned = K> + Hash + Eq,
    S: BuildHasher
[src]

Loading content...

Implementors

Loading content...