pub struct HashMap<K, V, S: SubscribersStore<(K, V), O>, O> { /* private fields */ }Expand description
Reactive hash map based on HashMap.
§Usage
use medea_reactive::collections::ObservableHashMap;
let mut map = ObservableHashMap::new();
// You can subscribe on insert action:
let mut inserts = map.on_insert();
map.insert("foo", "bar");
let (key, val) = inserts.next()
.await
.unwrap();
assert_eq!(key, "foo");
assert_eq!(val, "bar");
// Also you can subscribe on remove action:
let mut removals = map.on_remove();
map.remove(&"foo");
let (key, val) = removals.next()
.await
.unwrap();
assert_eq!(key, "foo");
assert_eq!(val, "bar");
// Remove subscription will also receive all items of the HashMap when it
// will be dropped:
map.insert("foo-1", "bar-1");
map.insert("foo-2", "bar-2");
drop(map);
let removed_items: HashMap<_, _> = removals.take(2)
.collect()
.await;
assert_eq!(removed_items["foo-1"], "bar-1");
assert_eq!(removed_items["foo-2"], "bar-2");§Waiting for subscribers to complete
use medea_reactive::collections::ProgressableHashMap;
let mut hash_map = ProgressableHashMap::new();
let mut on_insert = hash_map.on_insert();
hash_map.insert(1, 1);
// hash_map.when_insert_processed().await; <- wouldn't be resolved
let value = on_insert.next().await.unwrap();
// hash_map.when_insert_processed().await; <- wouldn't be resolved
drop(value);
hash_map.when_insert_processed().await; // will be resolvedImplementations§
Source§impl<K, V> HashMap<K, V, SubStore<(K, V)>, Guarded<(K, V)>>
impl<K, V> HashMap<K, V, SubStore<(K, V)>, Guarded<(K, V)>>
Sourcepub fn when_insert_processed(&self) -> Processed<'static> ⓘ
pub fn when_insert_processed(&self) -> Processed<'static> ⓘ
Returns Future resolving when all insertion updates will be
processed by HashMap::on_insert() subscribers.
Sourcepub fn when_remove_processed(&self) -> Processed<'static> ⓘ
pub fn when_remove_processed(&self) -> Processed<'static> ⓘ
Returns Future resolving when all remove updates will be processed
by HashMap::on_remove() subscribers.
Sourcepub fn when_all_processed(&self) -> AllProcessed<'static> ⓘ
pub fn when_all_processed(&self) -> AllProcessed<'static> ⓘ
Returns Future resolving when all insert and remove updates will be
processed by subscribers.
Source§impl<K, V, S: SubscribersStore<(K, V), O>, O> HashMap<K, V, S, O>
impl<K, V, S: SubscribersStore<(K, V), O>, O> HashMap<K, V, S, O>
Source§impl<K, V, S, O> HashMap<K, V, S, O>
impl<K, V, S, O> HashMap<K, V, S, O>
Sourcepub fn replay_on_insert(&self) -> LocalBoxStream<'static, O>
pub fn replay_on_insert(&self) -> LocalBoxStream<'static, O>
Sourcepub fn on_insert_with_replay(&self) -> LocalBoxStream<'static, O>
pub fn on_insert_with_replay(&self) -> LocalBoxStream<'static, O>
Chains HashMap::replay_on_insert() with a HashMap::on_insert().
Source§impl<K, V, S, O> HashMap<K, V, S, O>
impl<K, V, S, O> HashMap<K, V, S, O>
Sourcepub fn get(&self, key: &K) -> Option<&V>
pub fn get(&self, key: &K) -> Option<&V>
Returns a reference to the value corresponding to the key.
Sourcepub fn get_mut(&mut self, key: &K) -> Option<&mut V>
pub fn get_mut(&mut self, key: &K) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key.
Note, that mutating of the returned value wouldn’t work same as
Observables and doesn’t spawns HashMap::on_insert() or
HashMap::on_remove() events. If you need subscriptions on value
changes then just wrap the value into an Observable and subscribe to
it.
Source§impl<K, V, S, O> HashMap<K, V, S, O>
impl<K, V, S, O> HashMap<K, V, S, O>
Sourcepub fn remove_not_present<A>(&mut self, other: &HashMap<K, A>)
pub fn remove_not_present<A>(&mut self, other: &HashMap<K, A>)
Removes all entries which are not present in the provided HashMap.
Sourcepub fn insert(&mut self, key: K, value: V) -> Option<V>
pub fn insert(&mut self, key: K, value: V) -> Option<V>
Inserts a key-value pair to this HashMap.
Emits HashMap::on_insert() event and may emit
HashMap::on_remove() event if insert replaces a value contained in
this HashMap.
Trait Implementations§
Source§impl<K: Clone, V: Clone, S: Clone + SubscribersStore<(K, V), O>, O: Clone> Clone for HashMap<K, V, S, O>
impl<K: Clone, V: Clone, S: Clone + SubscribersStore<(K, V), O>, O: Clone> Clone for HashMap<K, V, S, O>
Source§impl<K: Debug, V: Debug, S: Debug + SubscribersStore<(K, V), O>, O: Debug> Debug for HashMap<K, V, S, O>
impl<K: Debug, V: Debug, S: Debug + SubscribersStore<(K, V), O>, O: Debug> Debug for HashMap<K, V, S, O>
Source§impl<K, V, S: SubscribersStore<(K, V), O>, O> Drop for HashMap<K, V, S, O>
impl<K, V, S: SubscribersStore<(K, V), O>, O> Drop for HashMap<K, V, S, O>
Source§fn drop(&mut self)
fn drop(&mut self)
Sends all key-values of a dropped HashMap to the
HashMap::on_remove subs.