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>

source

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.

source

pub fn next_now(&mut self) -> T
where 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.

source

pub fn get(&self) -> T
where 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 not marked as observed such that a subsequent call of next or next_ref will return the same value again.

source

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.

source

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.

source

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>

source

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()).

source

pub fn clone_reset(&self) -> Self
where L::SubscriberState<T>: Clone,

Clone this Subscriber and reset the observed version of the inner value.

This is equivalent to using the regular clone method and calling reset on the clone afterwards.

Trait Implementations§

source§

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§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T, L: Lock> Debug for Subscriber<T, L>
where L::SubscriberState<T>: Debug,

source§

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

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

impl<T: Clone> Stream for Subscriber<T>

§

type Item = T

Values yielded by the stream.
source§

fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Self::Item>>

Attempt to pull out the next value of this stream, registering the current task for wakeup if the value is not yet available, and returning None if the stream is exhausted. Read more
source§

fn size_hint(&self) -> (usize, Option<usize>)

Returns the bounds on the remaining length of the stream. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.
source§

impl<S, T, E> TryStream for S
where S: Stream<Item = Result<T, E>> + ?Sized,

§

type Ok = T

The type of successful values yielded by this future
§

type Error = E

The type of failures yielded by this future
source§

fn try_poll_next( self: Pin<&mut S>, cx: &mut Context<'_>, ) -> Poll<Option<Result<<S as TryStream>::Ok, <S as TryStream>::Error>>>

Poll this TryStream as if it were a Stream. Read more
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more