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

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();

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);

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));

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));

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())

Returns the number of elements in the MapBuilder.

Examples
use puff_rs::types::MapBuilder;

let mut map = MapBuilder::new();
assert_eq!(map.len(), 0);
map.insert(1, 2);
assert_eq!(map.len(), 1);

Convert the MapBuilder into a Read-Only Map that can be shared between Tasks.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Converts to this type from a reference to the input type.
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more