Struct puff_rs::types::map::Map

source ·
pub struct Map<K: Clone, V: Clone>(_);
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

Create a new empty Map

Examples
use puff_rs::types::Map;
let map: Map<u32, u32> = Map::new();

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

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

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

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

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

The length of the Map

Examples
use puff_rs::types::Map;
let map: Map<i32, i32> = Map::new();
assert_eq!(map.len(), 0)

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

Iterate over all items, cloning their references.

Iterate over all keys, cloning their references.

Iterate over all values, cloning their references.

Returns a reference to the underlying raw HashMap

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Deserialize this value from the given Serde deserializer. Read more
Serialize this value into the given Serde serializer. Read more

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