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

Implementations

Checks if there is a message in the channel without blocking. Returns:

  • Ok(message) if there was a message in the channel.
  • Err(Empty) if the Sender is alive, but has not yet sent a message.
  • Err(Disconnected) if the Sender was dropped before sending anything or if the message has already been extracted by a previous receive call.

If a message is returned, the channel is disconnected and any subsequent receive operation using this receiver will return an error.

This method is completely lock-free and wait-free. The only thing it does is an atomic integer load of the channel state. And if there is a message in the channel it additionally performs one atomic integer store and copies the message from the heap to the stack for returning it.

Attempts to wait for a message from the Sender, returning an error if the channel is disconnected.

This method will always block the current thread if there is no data available and it is still possible for the message to be sent. Once the message is sent to the corresponding Sender, then this receiver will wake up and return that message.

If the corresponding Sender has disconnected (been dropped), or it disconnects while this call is blocking, this call will wake up and return Err to indicate that the message can never be received on this channel.

If a sent message has already been extracted from this channel this method will return an error.

Panics

Panics if called after this receiver has been polled asynchronously.

Attempts to wait for a message from the Sender, returning an error if the channel is disconnected. This is a non consuming version of Receiver::recv, but with a bit worse performance. Prefer [Receiver::recv] if your code allows consuming the receiver.

If a message is returned, the channel is disconnected and any subsequent receive operation using this receiver will return an error.

Panics

Panics if called after this receiver has been polled asynchronously.

Like Receiver::recv, but will not block longer than timeout. Returns:

  • Ok(message) if there was a message in the channel before the timeout was reached.
  • Err(Timeout) if no message arrived on the channel before the timeout was reached.
  • Err(Disconnected) if the sender was dropped before sending anything or if the message has already been extracted by a previous receive call.

If a message is returned, the channel is disconnected and any subsequent receive operation using this receiver will return an error.

If the supplied timeout is so large that Rust’s Instant type can’t represent this point in the future this falls back to an indefinitely blocking receive operation.

Panics

Panics if called after this receiver has been polled asynchronously.

Like Receiver::recv, but will not block longer than until deadline. Returns:

  • Ok(message) if there was a message in the channel before the deadline was reached.
  • Err(Timeout) if no message arrived on the channel before the deadline was reached.
  • Err(Disconnected) if the sender was dropped before sending anything or if the message has already been extracted by a previous receive call.

If a message is returned, the channel is disconnected and any subsequent receive operation using this receiver will return an error.

Panics

Panics if called after this receiver has been polled asynchronously.

Trait Implementations

Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more
The type of value produced on completion.
Attempt to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The output that the future will produce on completion.
Which kind of future are we turning this into?
Creates a future from a value. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.