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

The receiving end of a channel.

Note: Cloning the receiver does not turn this channel into a broadcast channel. Each message will only be received by a single receiver. This is useful for implementing work stealing for concurrent programs.

Implementations§

§

impl<T> Receiver<T>

pub fn recv_async(&self) -> RecvFut<'_, T>

Asynchronously receive a value from the channel, returning an error if all senders have been dropped. If the channel is empty, the returned future will yield to the async runtime.

pub fn into_recv_async<'a>(self) -> RecvFut<'a, T>

Convert this receiver into a future that asynchronously receives a single message from the channel, returning an error if all senders have been dropped. If the channel is empty, this future will yield to the async runtime.

pub fn stream(&self) -> RecvStream<'_, T>

Create an asynchronous stream that uses this receiver to asynchronously receive messages from the channel. The receiver will continue to be usable after the stream has been dropped.

pub fn into_stream<'a>(self) -> RecvStream<'a, T>

Convert this receiver into a stream that allows asynchronously receiving messages from the channel.

§

impl<T> Receiver<T>

pub fn try_recv(&self) -> Result<T, TryRecvError>

Attempt to fetch an incoming value from the channel associated with this receiver, returning an error if the channel is empty or if all senders have been dropped.

pub fn recv(&self) -> Result<T, RecvError>

Wait for an incoming value from the channel associated with this receiver, returning an error if all senders have been dropped.

pub fn recv_deadline(&self, deadline: Instant) -> Result<T, RecvTimeoutError>

Wait for an incoming value from the channel associated with this receiver, returning an error if all senders have been dropped or the deadline has passed.

pub fn recv_timeout(&self, dur: Duration) -> Result<T, RecvTimeoutError>

Wait for an incoming value from the channel associated with this receiver, returning an error if all senders have been dropped or the timeout has expired.

pub fn iter(&self) -> Iter<'_, T>

Create a blocking iterator over the values received on the channel that finishes iteration when all senders have been dropped.

You can also create a self-owned iterator with Receiver::into_iter.

pub fn try_iter(&self) -> TryIter<'_, T>

A non-blocking iterator over the values received on the channel that finishes iteration when all senders have been dropped or the channel is empty.

pub fn drain(&self) -> Drain<'_, T>

Take all msgs currently sitting in the channel and produce an iterator over them. Unlike try_iter, the iterator will not attempt to fetch any more values from the channel once the function has been called.

pub fn is_disconnected(&self) -> bool

Returns true if all senders for this channel have been dropped.

pub fn is_empty(&self) -> bool

Returns true if the channel is empty. Note: Zero-capacity channels are always empty.

pub fn is_full(&self) -> bool

Returns true if the channel is full. Note: Zero-capacity channels are always full.

pub fn len(&self) -> usize

Returns the number of messages in the channel.

pub fn capacity(&self) -> Option<usize>

If the channel is bounded, returns its capacity.

pub fn sender_count(&self) -> usize

Get the number of senders that currently exist.

pub fn receiver_count(&self) -> usize

Get the number of receivers that currently exist, including this one.

pub fn same_channel(&self, other: &Receiver<T>) -> bool

Returns whether the receivers are belong to the same channel.

Trait Implementations§

§

impl<T> Clone for Receiver<T>

§

fn clone(&self) -> Receiver<T>

Clone this receiver. Receiver acts as a handle to the ending a channel. Remaining channel contents will only be cleaned up when all senders and the receiver have been dropped.

Note: Cloning the receiver does not turn this channel into a broadcast channel. Each message will only be received by a single receiver. This is useful for implementing work stealing for concurrent programs.

1.0.0 · source§

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

Performs copy-assignment from source. Read more
§

impl<T> Debug for Receiver<T>

§

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

Formats the value using the given formatter. Read more
§

impl<T> Drop for Receiver<T>

§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

impl<'a, T> IntoIterator for &'a Receiver<T>

This exists as a shorthand for Receiver::iter.

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
§

fn into_iter(self) -> <&'a Receiver<T> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
§

impl<T> IntoIterator for Receiver<T>

§

fn into_iter(self) -> <Receiver<T> as IntoIterator>::IntoIter

Creates a self-owned but semantically equivalent alternative to Receiver::iter.

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Receiver<T>

§

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

§

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

§

impl<T> Unpin for Receiver<T>

§

impl<T> UnwindSafe for Receiver<T>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

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> 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 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere 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 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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

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