Struct medea_reactive::collections::vec::Vec [−][src]
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]
T: Clone + 'static,
pub fn when_push_processed(&self) -> Processed<'static>ⓘ
[src]
Returns Future
resolving when all push updates will be processed by
Vec::on_push()
subscribers.
pub fn when_remove_processed(&self) -> Processed<'static>ⓘ
[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]
Notable traits for AllProcessed<'a, T>
impl<'a, T> Future for AllProcessed<'a, T> type Output = T;
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]
impl<T, S, O> Vec<T, S, O> where
T: Clone,
S: SubscribersStore<T, O>,
O: 'static,
[src]
T: Clone,
S: SubscribersStore<T, O>,
O: 'static,
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]
Trait Implementations
impl<T, S, O> AsRef<[T]> for Vec<T, S, O> where
T: Clone,
S: SubscribersStore<T, O>,
[src]
T: Clone,
S: SubscribersStore<T, O>,
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]
Auto Trait Implementations
impl<T, S, O> RefUnwindSafe for Vec<T, S, O> where
O: RefUnwindSafe,
S: RefUnwindSafe,
T: RefUnwindSafe,
[src]
O: RefUnwindSafe,
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, S, O> Send for Vec<T, S, O> where
O: Send,
S: Send,
T: Send,
[src]
O: Send,
S: Send,
T: Send,
impl<T, S, O> Sync for Vec<T, S, O> where
O: Sync,
S: Sync,
T: Sync,
[src]
O: Sync,
S: Sync,
T: Sync,
impl<T, S, O> Unpin for Vec<T, S, O> where
O: Unpin,
S: Unpin,
T: Unpin,
[src]
O: Unpin,
S: Unpin,
T: Unpin,
impl<T, S, O> UnwindSafe for Vec<T, S, O> where
O: UnwindSafe,
S: UnwindSafe,
T: UnwindSafe,
[src]
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>,