Struct puff_rs::types::map_builder::MapBuilder
source · pub struct MapBuilder<K, V>(_);Expand description
Fast Key Value structure for local construction.
Puff’s MapBuilder type uses std::collections::hash_map::HashMap under the hood. HashMaps are not
sharable structures and so need to be wrapped in an Arc to be shared between threads and cheaply copied.
You should use a MapBuilder and convert it into a Map when you are done writing to it.
Maps can only be constructed from types implementing IntoMapBuilder.
Examples
use puff_rs::types::MapBuilder;
let mut builder = MapBuilder::new();
builder.insert(42, 0);
let map = builder.into_map();Implementations
sourceimpl<K, T> MapBuilder<K, T>where
K: Puff + Hash + Eq,
T: Puff,
impl<K, T> MapBuilder<K, T>where
K: Puff + Hash + Eq,
T: Puff,
sourcepub fn new() -> MapBuilder<K, T>
pub fn new() -> MapBuilder<K, T>
Creates an empty MapBuilder.
The hash map is initially created with a capacity of 0, so it will not allocate until it is first inserted into.
Examples
use puff_rs::types::{Text, MapBuilder};
let mut map: MapBuilder<Text, i32> = MapBuilder::new();sourcepub fn with_capacity(capacity: usize) -> MapBuilder<K, T>
pub fn with_capacity(capacity: usize) -> MapBuilder<K, T>
Creates an empty MapBuilder with the specified capacity.
The hash map will be able to hold at least capacity elements without
reallocating. If capacity is 0, the hash map will not allocate.
Examples
use puff_rs::types::{Text, MapBuilder};
let mut map: MapBuilder<Text, i32> = MapBuilder::with_capacity(10);sourcepub fn insert(&mut self, key: K, item: T) -> Option<T>
pub fn insert(&mut self, key: K, item: T) -> Option<T>
Inserts a key-value pair into the MapBuilder.
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. See the [module-level
documentation] for more.
Examples
use puff_rs::types::MapBuilder;
let mut map = MapBuilder::new();
assert_eq!(map.insert(37, 42), None);
assert_eq!(map.is_empty(), false);
map.insert(37, 10);
assert_eq!(map.insert(37, 13), Some(10));sourcepub fn get(&self, index: K) -> Option<T>
pub fn get(&self, index: K) -> Option<T>
Returns a reference to the value corresponding to the key.
Examples
use puff_rs::types::MapBuilder;
let mut map = MapBuilder::new();
map.insert(1, 2);
assert_eq!(map.get(1), Some(2));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::MapBuilder;
let map: MapBuilder<usize, usize> = MapBuilder::new();
assert!(map.is_empty())Trait Implementations
sourceimpl<K: Clone, V: Clone> Clone for MapBuilder<K, V>
impl<K: Clone, V: Clone> Clone for MapBuilder<K, V>
sourcefn clone(&self) -> MapBuilder<K, V>
fn clone(&self) -> MapBuilder<K, V>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more