pub struct ObservableHashMap<K, V, Codec = Default> { /* private fields */ }
Expand description

A hash map that emits an event for each change.

Use subscribe to obtain an event stream that can be used for building a mirror of this hash map.

Implementations

Creates an empty observable hash map.

Sets the error handler function that is called when sending an event fails.

Subscribes to change events from this observable hash map.

The current contents of the hash map is included with the subscription.

buffer specifies the maximum size of the event buffer for this subscription in number of events. If it is exceeded the subscription is shed and the receiver gets a RecvError::Lagged.

Subscribes to change events from this observable hash map with incremental sending of the current contents.

The current contents of the hash map are sent incrementally.

buffer specifies the maximum size of the event buffer for this subscription in number of events. If it is exceeded the subscription is shed and the receiver gets a RecvError::Lagged.

Current number of subscribers.

Inserts a value under a key.

A HashMapEvent::Set change event is sent.

Returns the value previously stored under the key, if any.

Panics

Panics when done has been called before.

Removes the value under the specified key.

A HashMapEvent::Remove change event is sent.

The value is returned.

Panics

Panics when done has been called before.

Removes all items.

A HashMapEvent::Clear change event is sent.

Panics

Panics when done has been called before.

Retains only the elements specified by the predicate.

A HashMapEvent::Remove change event is sent for every element that is removed.

Panics

Panics when done has been called before.

Gets a mutable reference to the value under the specified key.

A HashMapEvent::Set change event is sent if the reference is accessed mutably.

Panics

Panics when done has been called before.

Mutably iterates over the key-value pairs.

A HashMapEvent::Set change event is sent for each value that is accessed mutably.

Panics

Panics when done has been called before.

Shrinks the capacity of the hash map as much as possible.

A HashMapEvent::ShrinkToFit change event is sent.

Panics

Panics when done has been called before.

Prevents further changes of this hash map and notifies are subscribers that no further events will occur.

Methods that modify the hash map will panic after this has been called. It is still possible to subscribe to this observable hash map.

Returns true if done has been called and further changes are prohibited.

Methods that modify the hash map will panic in this case.

Extracts the underlying hash map.

If done has not been called before this method, subscribers will receive an error.

Methods from Deref<Target = HashMap<K, V>>

Returns the number of elements the map can hold without reallocating.

This number is a lower bound; the HashMap<K, V> might be able to hold more, but is guaranteed to be able to hold at least this many.

Examples
use std::collections::HashMap;
let map: HashMap<i32, i32> = HashMap::with_capacity(100);
assert!(map.capacity() >= 100);

An iterator visiting all keys in arbitrary order. The iterator element type is &'a K.

Examples
use std::collections::HashMap;

let map = HashMap::from([
    ("a", 1),
    ("b", 2),
    ("c", 3),
]);

for key in map.keys() {
    println!("{}", key);
}

An iterator visiting all values in arbitrary order. The iterator element type is &'a V.

Examples
use std::collections::HashMap;

let map = HashMap::from([
    ("a", 1),
    ("b", 2),
    ("c", 3),
]);

for val in map.values() {
    println!("{}", val);
}

An iterator visiting all key-value pairs in arbitrary order. The iterator element type is (&'a K, &'a V).

Examples
use std::collections::HashMap;

let map = HashMap::from([
    ("a", 1),
    ("b", 2),
    ("c", 3),
]);

for (key, val) in map.iter() {
    println!("key: {} val: {}", key, val);
}

Returns the number of elements in the map.

Examples
use std::collections::HashMap;

let mut a = HashMap::new();
assert_eq!(a.len(), 0);
a.insert(1, "a");
assert_eq!(a.len(), 1);

Returns true if the map contains no elements.

Examples
use std::collections::HashMap;

let mut a = HashMap::new();
assert!(a.is_empty());
a.insert(1, "a");
assert!(!a.is_empty());

Returns a reference to the map’s BuildHasher.

Examples
use std::collections::HashMap;
use std::collections::hash_map::RandomState;

let hasher = RandomState::new();
let map: HashMap<i32, i32> = HashMap::with_hasher(hasher);
let hasher: &RandomState = map.hasher();

Returns a reference to the value corresponding to the key.

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

Examples
use std::collections::HashMap;

let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.get(&1), Some(&"a"));
assert_eq!(map.get(&2), None);

Returns the key-value pair corresponding to the supplied key.

The supplied key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

Examples
use std::collections::HashMap;

let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.get_key_value(&1), Some((&1, &"a")));
assert_eq!(map.get_key_value(&2), None);

Returns true if the map contains a value for the specified key.

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

Examples
use std::collections::HashMap;

let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.contains_key(&1), true);
assert_eq!(map.contains_key(&2), false);
source

pub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S>

🔬 This is a nightly-only experimental API. (hash_raw_entry)

Creates a raw immutable entry builder for the HashMap.

Raw entries provide the lowest level of control for searching and manipulating a map. They must be manually initialized with a hash and then manually searched.

This is useful for

  • Hash memoization
  • Using a search key that doesn’t work with the Borrow trait
  • Using custom comparison logic without newtype wrappers

Unless you are in such a situation, higher-level and more foolproof APIs like get should be preferred.

Immutable raw entries have very limited use; you might instead want raw_entry_mut.

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The resulting type after dereferencing.

Dereferences the value.

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Performs the conversion.

Performs the conversion.

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.

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.

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