Skip to main content

Consumer

Struct Consumer 

Source
pub struct Consumer<T> { /* private fields */ }
Expand description

The consuming side of a shared state channel.

Consumers have read-only access to the shared value and are notified when a producer modifies it. Cloning a consumer increments the consumer reference count. When the last consumer is dropped, all waiters (e.g. Producer::unused) are notified.

Implementations§

Source§

impl<T> Consumer<T>

Source

pub fn poll<F, R>(&self, waiter: &Waiter, f: F) -> Poll<Result<R, Ref<'_, T>>>
where F: FnMut(&Ref<'_, T>) -> Poll<R>,

Poll the shared state with a closure.

Calls f with a Ref. If f returns Poll::Pending and the channel is still open, registers the Waiter for notification. Returns Err(Ref) if the channel has been closed while the condition returned by f is still pending.

Source

pub fn poll_closed(&self, waiter: &Waiter) -> Poll<()>

Poll for channel closure, registering the waiter if still open.

Source

pub async fn wait<F, R>(&self, f: F) -> Result<R, Ref<'_, T>>
where F: FnMut(&Ref<'_, T>) -> Poll<R> + Unpin, R: Unpin,

Wait for the closure to return Poll::Ready, re-polling on each state change.

Returns Ok(R) when the closure returns Poll::Ready, or Err(Ref) with read-only access to the final state if the channel closes first.

Source

pub async fn closed(&self)

Wait until the channel is closed.

Source

pub fn produce(&self) -> Option<Producer<T>>

Upgrade to a Producer, returning None if the state is already closed.

Source

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

Get read-only access to the shared state.

Source

pub fn same_channel(&self, other: &Self) -> bool

Returns true if both consumers share the same underlying state.

Trait Implementations§

Source§

impl<T> Clone for Consumer<T>

Source§

fn clone(&self) -> Self

Returns a duplicate 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: Debug> Debug for Consumer<T>

Source§

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

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

impl<T> Drop for Consumer<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Consumer<T>

§

impl<T> RefUnwindSafe for Consumer<T>

§

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

§

impl<T> Sync for Consumer<T>
where T: Send,

§

impl<T> Unpin for Consumer<T>

§

impl<T> UnsafeUnpin for Consumer<T>

§

impl<T> UnwindSafe for Consumer<T>

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 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.