Expand description
Fast Read-Only Key Value structures.
Puff’s Map type uses std::collections::hash_map::HashMap under the hood. However, in order
for it to handle cheap clones, it is wrapped in an Arc, making it read-only.
Maps can only be constructed from types implementing IntoMapBuilder.
use puff_rs::types::Map;
let map = Map::from_builder(vec![(123, 456)]);
assert_eq!(map.get(123), Some(456))Implementations
sourceimpl<K, T> Map<K, T>where
K: Puff + Hash + Eq,
T: Puff + Send + 'static,
impl<K, T> Map<K, T>where
K: Puff + Hash + Eq,
T: Puff + Send + 'static,
sourcepub fn from_builder<B: IntoMapBuilder<K, T>>(builder: B) -> Map<K, T>
pub fn from_builder<B: IntoMapBuilder<K, T>>(builder: B) -> Map<K, T>
Take a datatype that implements IntoMapBuilder and turn it into a read-only Map
Examples
use puff_rs::types::Map;
let map = Map::from_builder(vec![(123, 456)]);sourcepub fn from_hash_map(hm: HashMap<K, T>) -> Map<K, T>
pub fn from_hash_map(hm: HashMap<K, T>) -> Map<K, T>
Create a new Map from a raw HashMap.
Examples
use std::collections::HashMap;
use puff_rs::types::Map;
let map: Map<i32, i32> = Map::from_hash_map(HashMap::new());sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the map contains no elements.
Examples
use puff_rs::types::Map;
let map: Map<i32, i32> = Map::new();
assert!(map.is_empty())sourcepub fn get(&self, index: K) -> Option<T>
pub fn get(&self, index: K) -> Option<T>
Returns the data associated with the key.
Examples
use puff_rs::types::Map;
let map = Map::from_builder(vec![(123, 456)]);
assert_eq!(map.get(123), Some(456))sourcepub fn get_key_value(&self, index: K) -> Option<(K, T)>
pub fn get_key_value(&self, index: K) -> Option<(K, T)>
Returns the key, value pair corresponding to the key
Examples
use puff_rs::types::Map;
let map = Map::from_builder(vec![(123, 456)]);
assert_eq!(map.get_key_value(123), Some((123, 456)))sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
The length of the Map
Examples
use puff_rs::types::Map;
let map: Map<i32, i32> = Map::new();
assert_eq!(map.len(), 0)sourcepub fn iter(&self) -> IntoIter<K, T>
pub fn iter(&self) -> IntoIter<K, T>
Iterate over the Map.
Note: normally calling .iter() on a Map iterates over (&K, &V),
however, puff’s Map cheaply clones the data so that concrete data is returned instead.
If this is not desirable, manually iterate over the underlying type using arc_hashmap.
This applies to all Iterators in Map (keys, values, items).
sourcepub fn values(self) -> IntoValues<K, T>
pub fn values(self) -> IntoValues<K, T>
Iterate over all values, cloning their references.
sourcepub fn arc_hashmap(self) -> Arc<HashMap<K, T>>
pub fn arc_hashmap(self) -> Arc<HashMap<K, T>>
Returns a reference to the underlying raw HashMap