Struct discro::Subscriber

source ·
pub struct Subscriber<T> { /* private fields */ }
Expand description

Read a shared value and receive change notifications asynchronously.

Implementations§

source§

impl<T> Subscriber<T>

source

pub fn read(&self) -> Ref<T>

Obtain a reference to the most recent value.

Outstanding borrows hold a read lock. Trying to read the value again while already holding a read lock might cause a deadlock!

source

pub fn read_ack(&mut self) -> Ref<T>

Obtain a reference to the most recent value and mark that value as seen by acknowledging it.

Returns a tuple with the borrowed value and a changed flag that indicates if changes have been detected and acknowledged.

Callers must be prepared to handle false positive results, i.e. if the changed flag returns true even though the shared value has not been modified. The accuracy of the changed flag depends on the underlying implementation.

Outstanding borrows hold a read lock. Trying to read the value again while already holding a read lock might cause a deadlock!

source

pub async fn changed(&mut self) -> Result<(), OrphanedSubscriberError>

Receive change notifications for the shared value.

Waits for a change notification, then marks the newest value as seen.

Errors

Returns Err(OrphanedSubscriberError) if the subscriber is disconnected from the publisher.

source

pub fn into_stream<U>( self, capture_fn: impl FnMut(&T) -> U ) -> impl Stream<Item = U>

Observe modifications as a stream of captured values.

The capture_fn closure is invoked on a borrowed value while the lock is held.

Returns a stream of captured values, starting with the current value.

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Subscriber<T>where T: RefUnwindSafe,

§

impl<T> Send for Subscriber<T>where T: Send,

§

impl<T> Sync for Subscriber<T>where T: Sync,

§

impl<T> Unpin for Subscriber<T>where T: Unpin,

§

impl<T> UnwindSafe for Subscriber<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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, U> TryFrom<U> for Twhere 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 Twhere 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.