Struct medea_reactive::collections::vec::Vec[][src]

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

Reactive vector based on Vec.

Usage

use medea_reactive::collections::ObservableVec;

let mut vec = ObservableVec::new();

// You can subscribe on push event:
let mut pushes = vec.on_push();

vec.push("foo");

let pushed_item = pushes.next().await.unwrap();
assert_eq!(pushed_item, "foo");

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

vec.remove(0);

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

// On Vec structure drop, all items will be sent to the on_remove stream:
vec.push("foo-1");
vec.push("foo-2");
drop(vec);
let removed_items: Vec<_> = removals.take(2)
    .collect()
    .await;
assert_eq!(removed_items[0], "foo-1");
assert_eq!(removed_items[1], "foo-2");

Waiting for subscribers to complete

use medea_reactive::collections::ProgressableVec;

let mut vec = ProgressableVec::new();

let mut on_push = vec.on_push();
vec.push(1);

// vec.when_push_processed().await; <- wouldn't be resolved
let value = on_push.next().await.unwrap();
// vec.when_push_processed().await; <- wouldn't be resolved
drop(value);

vec.when_push_processed().await; // will be resolved

Implementations

impl<T> Vec<T, SubStore<T>, Guarded<T>> where
    T: Clone + 'static, 
[src]

pub fn when_push_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 Vec::on_push() 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 Vec::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 push and remove updates will be processed by subscribers.

impl<T, S: SubscribersStore<T, O>, O> Vec<T, S, O>[src]

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

Returns new empty Vec.

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

An iterator visiting all elements in arbitrary order. The iterator element type is &'a T.

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

Returns the Stream to which the pushed values will be sent.

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

Returns the Stream to which the removed values will be sent.

Note that to this Stream will be sent all items of the Vec on drop.

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

pub fn push(&mut self, value: T)[src]

Appends a value to the back of this Vec.

This will produce Vec::on_push() event.

pub fn remove(&mut self, index: usize) -> T[src]

Removes and returns the value at position index within this Vec, shifting all values after it to the left.

This will produce Vec::on_remove() event.

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

Returns Stream containing values from this Vec.

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

Trait Implementations

impl<T, S, O> AsRef<[T]> for Vec<T, S, O> where
    T: Clone,
    S: SubscribersStore<T, O>, 
[src]

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

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

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

fn drop(&mut self)[src]

Sends all items of a dropped Vec to the Vec::on_remove() subscriptions.

impl<T, S: SubscribersStore<T, O>, O> From<Vec<T, Global>> for Vec<T, S, O>[src]

impl<'a, T, S: SubscribersStore<T, O>, O> IntoIterator for &'a Vec<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 Vec<T, S, O> where
    O: RefUnwindSafe,
    S: RefUnwindSafe,
    T: RefUnwindSafe

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

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

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

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