Struct medea_reactive::collections::hash_set::HashSet[][src]

pub struct HashSet<T, S: SubscribersStore<T, O>, O> { /* fields omitted */ }

Reactive hash set based on HashSet.

Usage

use medea_reactive::collections::ObservableHashSet;

let mut set = ObservableHashSet::new();

// You can subscribe on insert action:
let mut inserts = set.on_insert();

set.insert("foo");

let item = inserts.next()
    .await
    .unwrap();
assert_eq!(item, "foo");

// Also you can subscribe on remove action:
let mut removals = set.on_remove();

set.remove(&"foo");

let removed_item = removals.next()
    .await
    .unwrap();
assert_eq!(removed_item, "foo");

// When you update HashSet by another HashSet all events will
// work fine:
set.insert("foo-1");
set.insert("foo-2");
set.insert("foo-3");

let mut set_for_update = HashSet::new();
set_for_update.insert("foo-1");
set_for_update.insert("foo-4");
set.update(set_for_update);

let removed_items: HashSet<_> = removals.take(2)
    .collect()
    .await;
let inserted_item = inserts.skip(3)
    .next()
    .await
    .unwrap();
assert!(removed_items.contains("foo-2"));
assert!(removed_items.contains("foo-3"));
assert_eq!(inserted_item, "foo-4");
assert!(set.contains(&"foo-1"));
assert!(set.contains(&"foo-4"));

Waiting for subscribers to complete

use medea_reactive::collections::ProgressableHashSet;

let mut hash_set = ProgressableHashSet::new();

let mut on_insert = hash_set.on_insert();
hash_set.insert(1);

// hash_set.when_insert_processed().await; <- wouldn't be resolved
let value = on_insert.next().await.unwrap();
// hash_set.when_insert_processed().await; <- wouldn't be resolved
drop(value);

hash_set.when_insert_processed().await; // will be resolved

Implementations

impl<T> HashSet<T, SubStore<T>, Guarded<T>> where
    T: 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 push updates will be processed by HashSet::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 HashSet::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<T, S: SubscribersStore<T, O>, O> HashSet<T, S, O>[src]

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

Creates new empty HashSet.

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

Returns Iterator visiting all values in an arbitrary order.

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

Returns Stream yielding inserted values to this HashSet.

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

Returns the Stream yielding removed values from this HashSet.

Note, that this Stream will yield all values of this HashSet on Drop.

impl<T, S, O> HashSet<T, S, O> where
    T: Clone + 'static,
    S: SubscribersStore<T, O>,
    O: 'static, 
[src]

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

Returns Stream containing values from this HashSet.

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

impl<T, S, O> HashSet<T, S, O> where
    T: Clone + Hash + Eq + 'static,
    S: SubscribersStore<T, O>, 
[src]

pub fn insert(&mut self, value: T) -> bool[src]

Adds the value to this HashSet.

If it didn’t have such value present, true is returned.

If it did have such value present, false is returned.

This will produce [HashSet::on_inser()t] event.

pub fn remove(&mut self, value: &T) -> Option<T>[src]

Removes the value from this HashSet and returns it, if any.

This will produce HashSet::on_remove() event.

pub fn update(&mut self, updated: HashSet<T>)[src]

Makes this HashSet exactly the same as the updated one.

It will calculate a diff between this HashSet and the updated, and will spawn HashSet::on_insert() and HashSet::on_remove() if the diff is not empty.

For the usage example you can read HashSet docs.

#[must_use]pub fn contains(&self, value: &T) -> bool[src]

Indicates whether this HashSet contains the value.

Trait Implementations

impl<T: Debug, S: Debug + SubscribersStore<T, O>, O: Debug> Debug for HashSet<T, S, O>[src]

impl<T, S, O> Default for HashSet<T, S, O> where
    S: SubscribersStore<T, O>, 
[src]

impl<T, S, O> Drop for HashSet<T, S, O> where
    S: SubscribersStore<T, O>, 
[src]

fn drop(&mut self)[src]

Sends all values of a dropped HashSet to the HashSet::on_remove() subscriptions.

impl<T, S, O> From<HashSet<T, RandomState>> for HashSet<T, S, O> where
    S: SubscribersStore<T, O>, 
[src]

impl<'a, T, S: SubscribersStore<T, O>, O> IntoIterator for &'a HashSet<T, S, O>[src]

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?

type Item = &'a T

The type of the elements being iterated over.

Auto Trait Implementations

impl<T, S, O> RefUnwindSafe for HashSet<T, S, O> where
    O: RefUnwindSafe,
    S: RefUnwindSafe,
    T: RefUnwindSafe

impl<T, S, O> Send for HashSet<T, S, O> where
    O: Send,
    S: Send,
    T: Send

impl<T, S, O> Sync for HashSet<T, S, O> where
    O: Sync,
    S: Sync,
    T: Sync

impl<T, S, O> Unpin for HashSet<T, S, O> where
    O: Unpin,
    S: Unpin,
    T: Unpin

impl<T, S, O> UnwindSafe for HashSet<T, S, O> where
    O: UnwindSafe,
    S: UnwindSafe,
    T: 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, 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.