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

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§

source§

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

source

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

Returns Future resolving when all push updates will be processed by Vec::on_push() subscribers.

source

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

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

source

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

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

source§

impl<T, S: SubscribersStore<T, O>, O> Vec<T, S, O>

source

pub fn new() -> Self

Returns new empty Vec.

source

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

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

source

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

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

source

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

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.

source§

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

source

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

Appends a value to the back of this Vec.

This will produce Vec::on_push() event.

source

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

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.

source

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

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§

source§

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

source§

fn as_ref(&self) -> &[T]

Converts this type into a shared reference of the (usually inferred) input type.
source§

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

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

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

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

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

source§

fn drop(&mut self)

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

source§

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

source§

fn from(from: Vec<T>) -> Self

Converts to this type from the input type.
source§

impl<'a, T, S: SubscribersStore<T, O>, O> IntoIterator for &'a Vec<T, S, O>

§

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.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.