Struct keos::thread::channel::Receiver

source ·
pub struct Receiver<T: Send + 'static> { /* private fields */ }
Expand description

The receiving half of channel type. This half can only be owned by one thread, but it can be cloned to receive to other threads.

Messages sent to the channel can be retrieved using recv.

Implementations§

source§

impl<T: Send + 'static> Receiver<T>

source

pub fn can_recv(&self) -> bool

Can receive a value through this channel.

source

pub fn has_sender(&self) -> bool

Does anyone can send a value through this channel.

source

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

Attempts to wait for a value on this receiver, returning an error if the corresponding channel has hung up.

This function will always block the current thread if there is no data available and it’s possible for more data to be sent. Once a message is sent to the corresponding Sender (or Sender), then this receiver will wake up and return that message.

If the corresponding Sender has disconnected, or it disconnects while this call is blocking, this call will wake up and return [Err] to indicate that no more messages can ever be received on this channel. However, since channels are buffered, messages sent before the disconnect will still be properly received.

source

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

Attempts to return a pending value on this receiver without blocking.

This method will never block the caller in order to wait for data to become available. Instead, this will always return immediately with a possible option of pending data on the channel.

This is useful for a flavor of “optimistic check” before deciding to block on a receiver.

Compared with recv, this function has two failure cases instead of one (one for disconnection, one for an empty buffer).

source

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

Returns an iterator that will block waiting for messages, but never [panic!]. It will return [None] when the channel has hung up.

source

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

Returns an iterator that will attempt to yield all pending values. It will return None if there are no more pending values or if the channel has hung up. The iterator will never [panic!] or block the user by waiting for values.

source

pub fn capacity(&self) -> usize

Get capacity of the channel.

Trait Implementations§

source§

impl<T: Send + 'static> Clone for Receiver<T>

source§

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

Returns a copy of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
source§

impl<T: Send + 'static> Debug for Receiver<T>

source§

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

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

impl<T: Send + 'static> Drop for Receiver<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'a, T: Send + 'static> IntoIterator for &'a Receiver<T>

§

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?
source§

fn into_iter(self) -> Iter<'a, T>

Creates an iterator from a value. Read more
source§

impl<T: Send + 'static> IntoIterator for Receiver<T>

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> IntoIter<T>

Creates an iterator from a value. Read more
source§

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

source§

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

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Receiver<T>

§

impl<T> Unpin for Receiver<T>

§

impl<T> !UnwindSafe for Receiver<T>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

const: unstable§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

const: unstable§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

const: unstable§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

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.
const: unstable§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.