eyeball

Struct 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>

Source§

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§

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

🔬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,

Source§

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>,

Source§

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>,

Source§

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,

Source§

type Ok = T

The type of successful values yielded by this future
Source§

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