Struct medea_reactive::collections::hash_map::HashMap[][src]

pub struct HashMap<K, V, S: SubscribersStore<(K, V), O>, O> { /* fields omitted */ }

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 resolved

Implementations

impl<K, V> HashMap<K, V, SubStore<(K, V)>, Guarded<(K, V)>> where
    K: Hash + Eq + Clone + 'static,
    V: Clone + 'static, 
[src]

pub fn when_insert_processed(&self) -> Processed<'static>

Notable traits for Processed<'a, T>

impl<'a, T> Future for Processed<'a, T> type Output = T;
[src]

Returns Future resolving when all insertion updates will be processed by HashMap::on_insert() subscribers.

pub fn when_remove_processed(&self) -> Processed<'static>

Notable traits for Processed<'a, T>

impl<'a, T> Future for Processed<'a, T> type Output = T;
[src]

Returns Future resolving when all remove updates will be processed by HashMap::on_remove() subscribers.

pub fn when_all_processed(&self) -> AllProcessed<'static>

Notable traits for AllProcessed<'a, T>

impl<'a, T> Future for AllProcessed<'a, T> type Output = T;
[src]

Returns Future resolving when all insert and remove updates will be processed by subscribers.

impl<K, V, S: SubscribersStore<(K, V), O>, O> HashMap<K, V, S, O>[src]

#[must_use]pub fn new() -> Self[src]

Creates new empty HashMap.

pub fn iter(&self) -> impl Iterator<Item = (&K, &V)>[src]

Iterator visiting all key-value pairs in an arbitrary order.

#[must_use]pub fn values(&self) -> Values<'_, K, V>[src]

Iterator visiting all values in an arbitrary order.

#[must_use]pub fn on_insert(&self) -> LocalBoxStream<'static, O>[src]

Returns Stream yielding inserted key-value pairs to this HashMap.

#[must_use]pub fn on_remove(&self) -> LocalBoxStream<'static, O>[src]

Returns Stream yielding removed key-value pairs from this HashMap.

Note, that this Stream will yield all key-value pairs of this HashMap on Drop.

impl<K, V, S, O> HashMap<K, V, S, O> where
    K: Clone,
    V: Clone,
    S: SubscribersStore<(K, V), O>,
    O: 'static, 
[src]

pub fn replay_on_insert(&self) -> LocalBoxStream<'static, O>[src]

Returns Stream containing values from this HashMap.

Returned Stream contains only current values. It won’t update on new inserts, but you can merge returned Stream with a HashMap::on_insert() Stream if you want to process current values and values that will be inserted.

pub fn on_insert_with_replay(&self) -> LocalBoxStream<'static, O>[src]

impl<K, V, S, O> HashMap<K, V, S, O> where
    K: Hash + Eq,
    S: SubscribersStore<(K, V), O>, 
[src]

#[must_use]pub fn get(&self, key: &K) -> Option<&V>[src]

Returns a reference to the value corresponding to the key.

#[must_use]pub fn get_mut(&mut self, key: &K) -> Option<&mut V>[src]

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.

impl<K, V, S, O> HashMap<K, V, S, O> where
    K: Hash + Eq + Clone,
    V: Clone,
    S: SubscribersStore<(K, V), O>, 
[src]

pub fn remove_not_present<A>(&mut self, other: &HashMap<K, A>)[src]

Removes all entries which are not present in the provided HashMap.

pub fn insert(&mut self, key: K, value: V) -> Option<V>[src]

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.

pub fn remove(&mut self, key: &K) -> Option<V>[src]

Removes the key from this HashMap, returning the value behind it, if any.

Emits HashMap::on_remove() event if value with provided key is removed from this HashMap.

Trait Implementations

impl<K: Clone, V: Clone, S: Clone + SubscribersStore<(K, V), O>, O: Clone> Clone for HashMap<K, V, S, O>[src]

impl<K: Debug, V: Debug, S: Debug + SubscribersStore<(K, V), O>, O: Debug> Debug for HashMap<K, V, S, O>[src]

impl<K, V, S: SubscribersStore<(K, V), O>, O> Default for HashMap<K, V, S, O>[src]

impl<K, V, S: SubscribersStore<(K, V), O>, O> Drop for HashMap<K, V, S, O>[src]

fn drop(&mut self)[src]

Sends all key-values of a dropped HashMap to the HashMap::on_remove subs.

impl<K, V, S: SubscribersStore<(K, V), O>, O> From<HashMap<K, V, RandomState>> for HashMap<K, V, S, O>[src]

impl<K, V, S: SubscribersStore<(K, V), O>, O> FromIterator<(K, V)> for HashMap<K, V, S, O> where
    K: Hash + Eq
[src]

impl<'a, K, V, S: SubscribersStore<(K, V), O>, O> IntoIterator for &'a HashMap<K, V, S, O>[src]

type IntoIter = Iter<'a, K, V>

Which kind of iterator are we turning this into?

type Item = (&'a K, &'a V)

The type of the elements being iterated over.

Auto Trait Implementations

impl<K, V, S, O> RefUnwindSafe for HashMap<K, V, S, O> where
    K: RefUnwindSafe,
    O: RefUnwindSafe,
    S: RefUnwindSafe,
    V: RefUnwindSafe

impl<K, V, S, O> Send for HashMap<K, V, S, O> where
    K: Send,
    O: Send,
    S: Send,
    V: Send

impl<K, V, S, O> Sync for HashMap<K, V, S, O> where
    K: Sync,
    O: Sync,
    S: Sync,
    V: Sync

impl<K, V, S, O> Unpin for HashMap<K, V, S, O> where
    K: Unpin,
    O: Unpin,
    S: Unpin,
    V: Unpin

impl<K, V, S, O> UnwindSafe for HashMap<K, V, S, O> where
    K: UnwindSafe,
    O: UnwindSafe,
    S: UnwindSafe,
    V: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.