Struct json_api::value::collections::map::Map
[−]
[src]
pub struct Map<K = Key, V = Value> where
K: Eq + Hash, { /* fields omitted */ }
A hash map implementation with consistent ordering.
Methods
impl<K, V> Map<K, V> where
K: Eq + Hash,
[src]
K: Eq + Hash,
fn new() -> Self
[src]
Creates an empty Map
.
Example
use json_api::value::{Key, Map, Value}; let mut map = Map::<Key, Value>::new();
fn with_capacity(capacity: usize) -> Self
[src]
Creates a new empty Map
, with specified capacity.
Example
let mut map = Map::with_capacity(2); map.insert("x", 1); map.insert("y", 2); // The next insert will likely require reallocation... map.insert("z", 3);
fn capacity(&self) -> usize
[src]
Returns the number of key-value pairs the map can hold without reallocating.
Example
let map = Map::<Key, Value>::with_capacity(2); assert!(map.capacity() >= 2);
fn clear(&mut self)
[src]
Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.
Example
let mut map = Map::new(); map.insert("x", 1); map.clear(); assert!(map.is_empty());
fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool where
Q: Equivalent<K> + Hash,
[src]
Q: Equivalent<K> + Hash,
Returns true if the map contains a value for the specified key.
Example
let mut map = Map::new(); map.insert(1, "a"); assert_eq!(map.contains_key(&1), true); assert_eq!(map.contains_key(&2), false);
fn drain(&mut self, range: RangeFull) -> Drain<K, V>
[src]
Clears the map, returning all key-value pairs as an iterator. Keeps the allocated memory for reuse.
Example
let mut map = Map::new(); map.insert("x", 1); map.insert("y", 2); for (key, value) in map.drain(..) { assert!(key == "x" || key == "y"); assert!(value == 1 || value == 2); } assert!(map.is_empty());
fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V> where
Q: Equivalent<K> + Hash,
[src]
Q: Equivalent<K> + Hash,
Returns a reference to the value corresponding to the key.
Example
let mut map = Map::new(); map.insert("x", 1); assert_eq!(map.get("x"), Some(&1)); assert_eq!(map.get("y"), None);
fn insert(&mut self, key: K, value: V) -> Option<V>
[src]
Inserts a key-value pair into the map.
If a value already existed for key, that old value is returned in
Some
; otherwise, None
is returned.
Example
let mut map = Map::new(); assert_eq!(map.insert("x", 1), None); assert_eq!(map.insert("x", 2), Some(1));
fn iter(&self) -> Iter<K, V>
[src]
Return an iterator visiting all the key-value pairs of the map in the order in which they were inserted.
Example
let mut map = Map::new(); map.insert("a", 1); map.insert("b", 2); map.insert("c", 3); for (key, value) in map.iter() { println!("key: {} value: {}", key, value); }
fn iter_mut(&mut self) -> IterMut<K, V>
[src]
Return an iterator visiting all the key-value pairs of the map in the order in which they were inserted, with mutable references to the values.
Example
let mut map = Map::new(); map.insert("a", 1); map.insert("b", 2); map.insert("c", 3); for (_, value) in map.iter_mut() { *value += 1; } for (key, value) in &map { println!("key: {} value: {}", key, value); }
fn keys(&self) -> Keys<K, V>
[src]
Return an iterator visiting all keys in the order in which they were inserted.
Example
let mut map = Map::new(); map.insert("a", 1); map.insert("b", 2); map.insert("c", 3); for key in map.keys() { println!("{}", key); }
fn len(&self) -> usize
[src]
Return the number of key-value pairs in the map.
Example
let mut map = Map::new(); assert_eq!(map.len(), 0); map.insert("x", 1); assert_eq!(map.len(), 1);
fn is_empty(&self) -> bool
[src]
Returns true if the map contains no elements.
Example
let mut map = Map::new(); assert!(map.is_empty()); map.insert("x", 1); assert!(!map.is_empty());
fn remove<Q: ?Sized>(&mut self, key: &Q) -> Option<V> where
Q: Equivalent<K> + Hash,
[src]
Q: Equivalent<K> + Hash,
Removes a key from the map, returning the value at the key if the key was previously in the map.
Example
let mut map = Map::new(); map.insert("x", 1); assert_eq!(map.remove("x"), Some(1)); assert_eq!(map.remove("x"), None);
fn reserve(&mut self, additional: usize)
[src]
Reserves capacity for at least additional more elements to be inserted
in the Map
. The collection may reserve more space to avoid frequent
reallocations.
Note
This method has yet to be fully implemented in the ordermap
crate.
Example
let mut map = Map::<Key, Value>::new(); map.reserve(10);
fn values(&self) -> Values<K, V>
[src]
Return an iterator visiting all values in the order in which they were inserted.
Example
let mut map = Map::new(); map.insert("a", 1); map.insert("b", 2); map.insert("c", 3); for value in map.values() { println!("{}", value); }
fn values_mut(&mut self) -> ValuesMut<K, V>
[src]
Return an iterator visiting all values mutably in the order in which they were inserted.
Example
let mut map = Map::new(); map.insert("a", 1); map.insert("b", 2); map.insert("c", 3); for value in map.values_mut() { *value += 1; } for value in map.values() { println!("{}", value); }
Trait Implementations
impl<K: Clone, V: Clone> Clone for Map<K, V> where
K: Eq + Hash,
[src]
K: Eq + Hash,
fn clone(&self) -> Map<K, V>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<K: Eq, V: Eq> Eq for Map<K, V> where
K: Eq + Hash,
[src]
K: Eq + Hash,
impl<K: PartialEq, V: PartialEq> PartialEq for Map<K, V> where
K: Eq + Hash,
[src]
K: Eq + Hash,
fn eq(&self, __arg_0: &Map<K, V>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Map<K, V>) -> bool
[src]
This method tests for !=
.
impl<K, V> Debug for Map<K, V> where
K: Debug + Eq + Hash,
V: Debug,
[src]
K: Debug + Eq + Hash,
V: Debug,
impl<K, V> Default for Map<K, V> where
K: Eq + Hash,
[src]
K: Eq + Hash,
impl<K, V> Extend<(K, V)> for Map<K, V> where
K: Eq + Hash,
[src]
K: Eq + Hash,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = (K, V)>,
[src]
I: IntoIterator<Item = (K, V)>,
Extends a collection with the contents of an iterator. Read more
impl<K, V> FromIterator<(K, V)> for Map<K, V> where
K: Eq + Hash,
[src]
K: Eq + Hash,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = (K, V)>,
[src]
I: IntoIterator<Item = (K, V)>,
Creates a value from an iterator. Read more
impl<K, V> IntoIterator for Map<K, V> where
K: Eq + Hash,
[src]
K: Eq + Hash,
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?
fn into_iter(self) -> Self::IntoIter
[src]
Creates an iterator from a value. Read more
impl<'a, K, V> IntoIterator for &'a Map<K, V> where
K: Eq + Hash,
[src]
K: Eq + Hash,
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?
fn into_iter(self) -> Self::IntoIter
[src]
Creates an iterator from a value. Read more
impl<'a, K, V> IntoIterator for &'a mut Map<K, V> where
K: Eq + Hash,
[src]
K: Eq + Hash,
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?
fn into_iter(self) -> Self::IntoIter
[src]
Creates an iterator from a value. Read more
impl<'de, K, V> Deserialize<'de> for Map<K, V> where
K: Deserialize<'de> + Eq + Hash,
V: Deserialize<'de>,
[src]
K: Deserialize<'de> + Eq + Hash,
V: Deserialize<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl<K, V> Serialize for Map<K, V> where
K: Eq + Hash + Serialize,
V: Serialize,
[src]
K: Eq + Hash + Serialize,
V: Serialize,