Trait assoc::vec::AssocStrictExt[][src]

pub trait AssocStrictExt<K, V> {
    fn entry(&mut self, key: K) -> Entry<'_, K, V>;
fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V>
    where
        K: Borrow<Q>,
        Q: PartialEq
;
fn get_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<&mut V>
    where
        K: Borrow<Q>,
        Q: PartialEq
;
fn insert(&mut self, key: K, value: V) -> Option<V>;
fn remove<Q: ?Sized>(&mut self, key: &Q) -> Option<V>
    where
        K: Borrow<Q>,
        Q: PartialEq
; }

This has the same API as AssocExt but with the additional constraint K: Eq.

use assoc::AssocStrictExt;

let map = vec![(1.0, 1), (2.0, 2)];
map.entry(1.0);

Required methods

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

Get a key’s entry for in-place manipulation.

use assoc::AssocStrictExt;

let mut count = Vec::new();
for x in vec!["a", "b", "c", "b"] {
    *count.entry(x).or_insert(0) += 1;
}
assert_eq!(count.get(&"b"), Some(&2));

fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V> where
    K: Borrow<Q>,
    Q: PartialEq
[src]

Get a reference to the value associated with a key.

use assoc::AssocStrictExt;

let map = vec![("a", 1), ("b", 2)];
assert_eq!(map.get(&"a"), Some(&1));

fn get_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<&mut V> where
    K: Borrow<Q>,
    Q: PartialEq
[src]

Get a mutable reference to the value associated with a key.

use assoc::AssocStrictExt;

let mut map = vec![("a", 1), ("b", 2)];
*map.get_mut(&"a").unwrap() += 1;
assert_eq!(map.get(&"a"), Some(&2));

fn insert(&mut self, key: K, value: V) -> Option<V>[src]

Insert a key-value pair into the associative array. If the map previously had the key, then the old value is returned. Otherwise, None is returned.

use assoc::AssocStrictExt;

let mut map = vec![("b", 3)];
assert_eq!(AssocStrictExt::insert(&mut map, "a", 1), None);
assert_eq!(AssocStrictExt::insert(&mut map, "a", 2), Some(1));

fn remove<Q: ?Sized>(&mut self, key: &Q) -> Option<V> where
    K: Borrow<Q>,
    Q: PartialEq
[src]

Remove a key from the map, returning the value if it was previously in the map.

use assoc::AssocStrictExt;

let mut map = vec![("a", 1)];
assert_eq!(AssocStrictExt::remove(&mut map, "a"), Some(1));
assert_eq!(AssocStrictExt::remove(&mut map, "a"), None);
Loading content...

Implementations on Foreign Types

impl<K, V> AssocStrictExt<K, V> for Vec<(K, V)> where
    K: Eq
[src]

Loading content...

Implementors

Loading content...