Struct medea_reactive::collections::vec::Vec
source · 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,
impl<T> Vec<T, SubStore<T>, Guarded<T>>where T: Clone + 'static,
sourcepub fn when_push_processed(&self) -> Processed<'static> ⓘ
pub fn when_push_processed(&self) -> Processed<'static> ⓘ
Returns Future
resolving when all push updates will be processed by
Vec::on_push()
subscribers.
sourcepub fn when_remove_processed(&self) -> Processed<'static> ⓘ
pub fn when_remove_processed(&self) -> Processed<'static> ⓘ
Returns Future
resolving when all remove updates will be processed
by Vec::on_remove()
subscribers.
sourcepub fn when_all_processed(&self) -> AllProcessed<'static> ⓘ
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>
impl<T, S: SubscribersStore<T, O>, O> Vec<T, S, O>
source§impl<T, S, O> Vec<T, S, O>where
T: Clone,
S: SubscribersStore<T, O>,
O: 'static,
impl<T, S, O> Vec<T, S, O>where T: Clone, S: SubscribersStore<T, O>, O: 'static,
sourcepub fn push(&mut self, value: T)
pub fn push(&mut self, value: T)
Appends a value to the back of this Vec
.
This will produce Vec::on_push()
event.
sourcepub fn remove(&mut self, index: usize) -> T
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.
sourcepub fn replay_on_push(&self) -> LocalBoxStream<'static, O>
pub fn replay_on_push(&self) -> LocalBoxStream<'static, O>
Trait Implementations§
source§impl<T, S: SubscribersStore<T, O>, O> Default for Vec<T, S, O>
impl<T, S: SubscribersStore<T, O>, O> Default for Vec<T, S, O>
source§impl<T, S: SubscribersStore<T, O>, O> Drop for Vec<T, S, O>
impl<T, S: SubscribersStore<T, O>, O> Drop for Vec<T, S, O>
source§fn drop(&mut self)
fn drop(&mut self)
Sends all items of a dropped Vec
to the Vec::on_remove()
subscriptions.
source§impl<'a, T, S: SubscribersStore<T, O>, O> IntoIterator for &'a Vec<T, S, O>
impl<'a, T, S: SubscribersStore<T, O>, O> IntoIterator for &'a Vec<T, S, O>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more