Struct eyeball::Subscriber
source · pub struct Subscriber<T, L: Lock = SyncLock> { /* private fields */ }
Expand description
A subscriber for updates of an Observable
.
Implementations§
source§impl<T> Subscriber<T>
impl<T> Subscriber<T>
sourcepub fn next(&mut self) -> Next<'_, T> ⓘwhere
T: Clone,
pub fn next(&mut self) -> Next<'_, T> ⓘwhere
T: Clone,
Wait for an update and get a clone of the updated value.
Awaiting returns Some(_)
after an update happened, or None
after the
Observable
(and all clones for shared::Observable
) is dropped.
This method is a convenience so you don’t have to import a Stream
extension trait such as futures::StreamExt
or
tokio_stream::StreamExt
.
sourcepub fn next_now(&mut self) -> Twhere
T: Clone,
pub fn next_now(&mut self) -> Twhere
T: Clone,
Get a clone of the inner value without waiting for an update.
If the returned value has not been observed by this subscriber before,
it is marked as observed such that a subsequent call of
next
or next_ref
won’t return the
same value again. See get
for a function that doesn’t
mark the value as observed.
sourcepub async fn next_ref(&mut self) -> Option<ObservableReadGuard<'_, T>>
pub async fn next_ref(&mut self) -> Option<ObservableReadGuard<'_, T>>
Wait for an update and get a read lock for the updated value.
Awaiting returns Some(_)
after an update happened, or None
after the
Observable
(and all clones for shared::Observable
) is dropped.
You can use this method to get updates of an Observable
where the
inner type does not implement Clone
. However, the Observable
will be locked (not updateable) while any read guards are alive.
sourcepub fn next_ref_now(&mut self) -> ObservableReadGuard<'_, T>
pub fn next_ref_now(&mut self) -> ObservableReadGuard<'_, T>
Lock the inner value for reading without waiting for an update.
Note that as long as the returned ObservableReadGuard
is kept alive,
the associated Observable
is locked and can not be updated.
If the returned value has not been observed by this subscriber before,
it is marked as observed such that a subsequent call of
next
or next_ref
won’t return the
same value again. See get
for a function that doesn’t
mark the value as observed.
sourcepub fn read(&self) -> ObservableReadGuard<'_, T>
pub fn read(&self) -> ObservableReadGuard<'_, T>
Lock the inner value for reading without waiting for an update.
Note that as long as the returned ObservableReadGuard
is kept alive,
the associated Observable
is locked and can not be updated.
If the returned value has not been observed by this subscriber before,
it is not marked as observed such that a subsequent call of
next
or next_ref
will return the
same value again.
source§impl<T, L: Lock> Subscriber<T, L>
impl<T, L: Lock> Subscriber<T, L>
sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the observed version of the inner value.
After calling this, it is guaranteed that the next call to
.next().await
or .next_ref().await
will resolve immediately.
This is only useful if you do this before passing the subscriber to some
other generic function or returning it, if you would be calling
.next().await
right afterwards, you can call
.next_now()
instead (same for .reset()
plus
.next_ref().await
, which can be expressed by
.next_ref_now()
).
sourcepub fn clone_reset(&self) -> Selfwhere
L::SubscriberState<T>: Clone,
pub fn clone_reset(&self) -> Selfwhere
L::SubscriberState<T>: Clone,
Trait Implementations§
source§impl<T, L: Lock> Clone for Subscriber<T, L>where
L::SubscriberState<T>: Clone,
impl<T, L: Lock> Clone for Subscriber<T, L>where
L::SubscriberState<T>: Clone,
Clone this Subscriber
exactly, including the observed version of the inner
value.
That means that if the original Subscriber
was up-to-date with the latest
value of the observable, the new one will be as well, and vice-versa.
See clone_reset
for a convenient way of making a new
Subscriber
from an existing one without inheriting the observed version of
the inner value.
source§impl<T, L: Lock> Debug for Subscriber<T, L>where
L::SubscriberState<T>: Debug,
impl<T, L: Lock> Debug for Subscriber<T, L>where
L::SubscriberState<T>: Debug,
source§impl<T: Clone> Stream for Subscriber<T>
impl<T: Clone> Stream for Subscriber<T>
Auto Trait Implementations§
impl<T, L> Freeze for Subscriber<T, L>where
<L as Lock>::SubscriberState<T>: Freeze,
impl<T, L> RefUnwindSafe for Subscriber<T, L>where
<L as Lock>::SubscriberState<T>: RefUnwindSafe,
impl<T, L> Send for Subscriber<T, L>where
<L as Lock>::SubscriberState<T>: Send,
impl<T, L> Sync for Subscriber<T, L>where
<L as Lock>::SubscriberState<T>: Sync,
impl<T, L> Unpin for Subscriber<T, L>where
<L as Lock>::SubscriberState<T>: Unpin,
impl<T, L> UnwindSafe for Subscriber<T, L>where
<L as Lock>::SubscriberState<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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)