Struct stry_common::utils::vec_map::VecMap[][src]

pub struct VecMap<K, V> { /* fields omitted */ }

A Vec backed map implementation.

Implementations

impl<K, V> VecMap<K, V>[src]

pub fn new() -> VecMap<K, V>[src]

Creates an empty VecMap.

The map is initially created with a capacity of 0, so it will not allocate until it is first inserted into.

Examples

use fenn::vec_map::VecMap;

let mut map: VecMap<&str, i32> = VecMap::new();

pub fn with_capacity(capacity: usize) -> VecMap<K, V>[src]

Creates an empty VecMap with the specified capacity.

The map will be able to hold at least capacity elements without reallocating. If capacity is 0, the map will not allocate.

Examples

use fenn::vec_map::VecMap;

let mut map: VecMap<&str, i32> = VecMap::with_capacity(10);

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

Returns the number of elements the map can hold without reallocating.

This number is a lower bound; the VecMap<K, V> might be able to hold more, but is guaranteed to be able to hold at least this many.

Examples

use fenn::vec_map::VecMap;

let map: VecMap<i32, i32> = VecMap::with_capacity(100);

assert!(map.capacity() >= 100);

pub fn keys(&self) -> Keys<'_, K, V>

Notable traits for Keys<'a, K, V>

impl<'a, K, V> Iterator for Keys<'a, K, V> type Item = &'a K;
[src]

An iterator visiting all keys in arbitrary order. The iterator element type is &'a K.

Examples

use fenn::vec_map::VecMap;

let mut map = VecMap::new();

map.insert("a", 1);
map.insert("b", 2);
map.insert("c", 3);

for key in map.keys() {
    println!("{}", key);
}

pub fn values(&self) -> Values<'_, K, V>

Notable traits for Values<'a, K, V>

impl<'a, K, V> Iterator for Values<'a, K, V> type Item = &'a V;
[src]

An iterator visiting all values in arbitrary order. The iterator element type is &'a V.

Examples

use fenn::vec_map::VecMap;

let mut map = VecMap::new();

map.insert("a", 1);
map.insert("b", 2);
map.insert("c", 3);

for val in map.values() {
    println!("{}", val);
}

pub fn values_mut(&mut self) -> ValuesMut<'_, K, V>

Notable traits for ValuesMut<'a, K, V>

impl<'a, K, V> Iterator for ValuesMut<'a, K, V> type Item = &'a mut V;
[src]

An iterator visiting all values mutably in arbitrary order. The iterator element type is &'a mut V.

Examples

use fenn::vec_map::VecMap;

let mut map = VecMap::new();

map.insert("a", 1);
map.insert("b", 2);
map.insert("c", 3);

for val in map.values_mut() {
    *val = *val + 10;
}

for val in map.values() {
    println!("{}", val);
}

pub fn iter(&self) -> Iter<'_, K, V>

Notable traits for Iter<'a, K, V>

impl<'a, K, V> Iterator for Iter<'a, K, V> type Item = (&'a K, &'a V);
[src]

An iterator visiting all key-value pairs in arbitrary order. The iterator element type is (&'a K, &'a V).

Examples

use fenn::vec_map::VecMap;

let mut map = VecMap::new();

map.insert("a", 1);
map.insert("b", 2);
map.insert("c", 3);

for (key, val) in map.iter() {
    println!("key: {} val: {}", key, val);
}

pub fn iter_mut(&mut self) -> IterMut<'_, K, V>

Notable traits for IterMut<'a, K, V>

impl<'a, K, V> Iterator for IterMut<'a, K, V> type Item = (&'a K, &'a mut V);
[src]

An iterator visiting all key-value pairs in arbitrary order, with mutable references to the values.

The iterator element type is (&'a K, &'a mut V).

Examples

use fenn::vec_map::VecMap;

let mut map = VecMap::new();

map.insert("a", 1);
map.insert("b", 2);
map.insert("c", 3);

// Update all values
for (_, val) in map.iter_mut() {
    *val *= 2;
}

for (key, val) in &map {
    println!("key: {} val: {}", key, val);
}

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

Returns the number of elements in the map.

Examples

use fenn::vec_map::VecMap;

let mut map = VecMap::new();

assert_eq!(map.len(), 0);

map.insert(1, "a");

assert_eq!(map.len(), 1);

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

Returns true if the map contains no elements.

Examples

use fenn::vec_map::VecMap;

let mut map = VecMap::new();

assert!(map.is_empty());

map.insert(1, "a");

assert!(!map.is_empty());

pub fn drain(&mut self) -> Drain<'_, K, V>

Notable traits for Drain<'a, K, V>

impl<'a, K, V> Iterator for Drain<'a, K, V> type Item = (K, V);
[src]

Clears the map, returning all key-value pairs as an iterator. Keeps the allocated memory for reuse.

Examples

use fenn::vec_map::VecMap;

let mut map = VecMap::new();

map.insert(1, "a");
map.insert(2, "b");

for (k, v) in map.drain().take(1) {
    assert!(k == 1 || k == 2);
    assert!(v == "a" || v == "b");
}

assert!(map.is_empty());

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

Retains only the elements specified by the predicate.

In other words, remove all pairs (k, v) such that f(&k,&mut v) returns false.

Examples

use fenn::vec_map::VecMap;

let mut map: VecMap<i32, i32> = (0..8).map(|x|(x, x*10)).collect();

map.retain(|&k, _| k % 2 == 0);

assert_eq!(map.len(), 4);

pub fn clear(&mut self)[src]

Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.

Examples

use fenn::vec_map::VecMap;

let mut map = VecMap::new();

map.insert(1, "a");

map.clear();

assert!(map.is_empty());

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

Reserves capacity for at least additional more elements to be inserted in the VecMap. The collection may reserve more space to avoid frequent reallocations.

Panics

Panics if the new allocation size overflows usize.

Examples

use fenn::vec_map::VecMap;

let mut map: VecMap<&str, i32> = VecMap::new();

map.reserve(10);

pub fn shrink_to_fit(&mut self)[src]

Shrinks the capacity of the map as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.

Examples

use fenn::vec_map::VecMap;

let mut map: VecMap<i32, i32> = VecMap::with_capacity(100);

map.insert(1, 2);
map.insert(3, 4);

assert!(map.capacity() >= 100);

map.shrink_to_fit();

assert!(map.capacity() >= 2);

pub fn truncate(&mut self, len: usize)[src]

impl<K, V> VecMap<K, V> where
    K: Eq
[src]

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

Gets the given key’s corresponding entry in the map for in-place manipulation.

Examples

use fenn::vec_map::VecMap;

let mut letters = VecMap::new();

for ch in "a short treatise on fungi".chars() {
    let counter = letters.entry(ch).or_insert(0);

    *counter += 1;
}

assert_eq!(letters[&'s'], 2);
assert_eq!(letters[&'t'], 3);
assert_eq!(letters[&'u'], 1);
assert_eq!(letters.get(&'y'), None);

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

Returns a reference to the value corresponding to the key.

The key may be any borrowed form of the map’s key type, but PartialEq on the borrowed form must match those for the key type.

Examples

use fenn::vec_map::VecMap;

let mut map = VecMap::new();

map.insert(1, "a");

assert_eq!(map.get(&1), Some(&"a"));
assert_eq!(map.get(&2), None);

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

Returns the key-value pair corresponding to the supplied key.

The supplied key may be any borrowed form of the map’s key type, but PartialEq on the borrowed form must match those for the key type.

Examples

use fenn::vec_map::VecMap;

let mut map = VecMap::new();

map.insert(1, "a");

assert_eq!(map.get_key_value(&1), Some((&1, &"a")));
assert_eq!(map.get_key_value(&2), None);

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

Returns the key-value pair corresponding to the supplied key, with a mutable reference to value.

The supplied key may be any borrowed form of the map’s key type, but PartialEq on the borrowed form must match those for the key type.

Examples

use fenn::vec_map::VecMap;

let mut map = VecMap::new();

map.insert(1, "a");

let (k, v) = map.get_key_value_mut(&1).unwrap();

assert_eq!(k, &1);
assert_eq!(v, &mut "a");

*v = "b";

assert_eq!(map.get_key_value_mut(&1), Some((&1, &mut "b")));
assert_eq!(map.get_key_value_mut(&2), None);

pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool where
    K: Borrow<Q>,
    Q: PartialEq<K>, 
[src]

Returns true if the map contains a value for the specified key.

The key may be any borrowed form of the map’s key type, but PartialEq on the borrowed form must match those for the key type.

Examples

use fenn::vec_map::VecMap;

let mut map = VecMap::new();

map.insert(1, "a");

assert_eq!(map.contains_key(&1), true);
assert_eq!(map.contains_key(&2), false);

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

Returns a mutable reference to the value corresponding to the key.

The key may be any borrowed form of the map’s key type, but PartialEq on the borrowed form must match those for the key type.

Examples

use fenn::vec_map::VecMap;

let mut map = VecMap::new();

map.insert(1, "a");

if let Some(x) = map.get_mut(&1) {
    *x = "b";
}

assert_eq!(map[&1], "b");

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

Inserts a key-value pair into the map.

If the map did not have this key present, None is returned.

If the map did have this key present, the value is updated, and the old value is returned. The key is not updated, though; this matters for types that can be == without being identical.

Examples

use fenn::vec_map::VecMap;

let mut map = VecMap::new();

assert_eq!(map.insert(37, "a"), None);
assert_eq!(map.is_empty(), false);

map.insert(37, "b");

assert_eq!(map.insert(37, "c"), Some("b"));
assert_eq!(map[&37], "c");

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

Removes a key from the map, returning the value at the key if the key was previously in the map.

The key may be any borrowed form of the map’s key type, but PartialEq on the borrowed form must match those for the key type.

Examples

use fenn::vec_map::VecMap;

let mut map = VecMap::new();

map.insert(1, "a");

assert_eq!(map.remove(&1), Some("a"));
assert_eq!(map.remove(&1), None);

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

Removes a key from the map, returning the stored key and value if the key was previously in the map.

The key may be any borrowed form of the map’s key type, but PartialEq on the borrowed form must match those for the key type.

Examples

use fenn::vec_map::VecMap;

let mut map = VecMap::new();

map.insert(1, "a");

assert_eq!(map.remove_entry(&1), Some((1, "a")));
assert_eq!(map.remove(&1), None);

Trait Implementations

impl<K, V> Clone for VecMap<K, V> where
    K: Clone,
    V: Clone
[src]

impl<K, V> Debug for VecMap<K, V> where
    K: Debug,
    V: Debug
[src]

impl<K, V> Default for VecMap<K, V>[src]

impl<K, V> Eq for VecMap<K, V> where
    K: Eq,
    V: Eq
[src]

impl<K, V> FromIterator<(K, V)> for VecMap<K, V> where
    K: Eq
[src]

impl<K, Q: ?Sized, V> Index<&'_ Q> for VecMap<K, V> where
    K: Eq + Borrow<Q>,
    Q: Eq
[src]

type Output = V

The returned type after indexing.

impl<K, Q: ?Sized, V> IndexMut<&'_ Q> for VecMap<K, V> where
    K: Eq + Borrow<Q>,
    Q: Eq
[src]

impl<'a, K, V> IntoIterator for &'a VecMap<K, V>[src]

type Item = (&'a K, &'a V)

The type of the elements being iterated over.

type IntoIter = Iter<'a, K, V>

Which kind of iterator are we turning this into?

impl<'a, K, V> IntoIterator for &'a mut VecMap<K, V>[src]

type Item = (&'a K, &'a mut V)

The type of the elements being iterated over.

type IntoIter = IterMut<'a, K, V>

Which kind of iterator are we turning this into?

impl<K, V> IntoIterator for VecMap<K, V>[src]

type Item = (K, V)

The type of the elements being iterated over.

type IntoIter = IntoIter<K, V>

Which kind of iterator are we turning this into?

impl<K, V> PartialEq<VecMap<K, V>> for VecMap<K, V> where
    K: PartialEq,
    V: PartialEq
[src]

impl<K, V> VecMapExt<K, V> for VecMap<K, V>[src]

Auto Trait Implementations

impl<K, V> RefUnwindSafe for VecMap<K, V> where
    K: RefUnwindSafe,
    V: RefUnwindSafe

impl<K, V> Send for VecMap<K, V> where
    K: Send,
    V: Send

impl<K, V> Sync for VecMap<K, V> where
    K: Sync,
    V: Sync

impl<K, V> Unpin for VecMap<K, V> where
    K: Unpin,
    V: Unpin

impl<K, V> UnwindSafe for VecMap<K, V> where
    K: UnwindSafe,
    V: UnwindSafe

Blanket Implementations

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

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

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

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

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

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

type Owned = T

The resulting type after obtaining ownership.

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<V, T> VZip<V> for T where
    V: MultiLane<T>,