Struct medea_reactive::collections::hash_set::HashSet [−][src]
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]
T: Clone + 'static,
pub fn when_insert_processed(&self) -> Processed<'static>ⓘ
[src]
Returns Future
resolving when all push updates will be processed by
HashSet::on_insert()
subscribers.
pub fn when_remove_processed(&self) -> Processed<'static>ⓘ
[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]
Notable traits for AllProcessed<'a, T>
impl<'a, T> Future for AllProcessed<'a, T> type Output = T;
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]
#[must_use]pub fn on_remove(&self) -> LocalBoxStream<'static, O>
[src]
impl<T, S, O> HashSet<T, S, O> where
T: Clone + 'static,
S: SubscribersStore<T, O>,
O: 'static,
[src]
T: Clone + 'static,
S: SubscribersStore<T, O>,
O: 'static,
pub fn replay_on_insert(&self) -> LocalBoxStream<'static, O>
[src]
impl<T, S, O> HashSet<T, S, O> where
T: Clone + Hash + Eq + 'static,
S: SubscribersStore<T, O>,
[src]
T: Clone + Hash + Eq + 'static,
S: SubscribersStore<T, O>,
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]
S: SubscribersStore<T, O>,
impl<T, S, O> Drop for HashSet<T, S, O> where
S: SubscribersStore<T, O>,
[src]
S: SubscribersStore<T, O>,
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]
S: SubscribersStore<T, O>,
impl<'a, T, S: SubscribersStore<T, O>, O> IntoIterator for &'a HashSet<T, S, O>
[src]
Auto Trait Implementations
impl<T, S, O> RefUnwindSafe for HashSet<T, S, O> where
O: RefUnwindSafe,
S: RefUnwindSafe,
T: RefUnwindSafe,
O: RefUnwindSafe,
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, S, O> Send for HashSet<T, S, O> where
O: Send,
S: Send,
T: Send,
O: Send,
S: Send,
T: Send,
impl<T, S, O> Sync for HashSet<T, S, O> where
O: Sync,
S: Sync,
T: Sync,
O: Sync,
S: Sync,
T: Sync,
impl<T, S, O> Unpin for HashSet<T, S, O> where
O: Unpin,
S: Unpin,
T: Unpin,
O: Unpin,
S: Unpin,
T: Unpin,
impl<T, S, O> UnwindSafe for HashSet<T, S, O> where
O: UnwindSafe,
S: UnwindSafe,
T: UnwindSafe,
O: UnwindSafe,
S: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,