docs

你正在阅读 v0.1.0 的文档。Nabi 0.1.0 已不再提供支持。 最新版本:v0.1.3 →

core::channel

本页内容

API 参考只有英文版,由标准库源代码中的英文文档注释生成。

message passing between threads. Multi-producer, multi-consumer: a Receiver copy shares the queue, and each value goes to one receiver. recv / send block the OS thread, recv_async / for await / send_async suspend the task (task::park: receivers on the meta address, senders one past it).

Structs

EmptySource

pub struct Empty

try_recv: nothing is queued, and a sender is still open.

Trait implementations 6

ClosedSource

pub struct Closed

try_recv: nothing is queued, and every sender has closed.

Trait implementations 6

SenderSource

pub struct Sender<T>

The sending end. Each clone is its own sender and is closed on its own; the channel closes when every sender has closed.

  • pub fn send(self, value: T) throws (SendError<T>)§

    Source

    Queue value (blocking while a bounded channel is full, and on a rendezvous channel until it is received). Throws it back if this sender was closed.

  • pub fn try_send(self, value: T) throws (TrySendError<T>)§

    Source

    Queue value without blocking: Full if a bounded channel is full, or if no receiver is waiting on a rendezvous channel.

  • pub const fn send_async(self, value: T) -> SendFuture<T>§

    Source

    try await tx.send_async(v) inside async code: like send, but suspends the task (not the thread) while a bounded channel is full, and on a rendezvous channel until the value is received.

  • pub fn close(self)§

    Source

    Close this sender; later sends on it throw Closed.

Trait implementations 3
  • impl<T> Debug for Sender<T>
  • impl<T> Drop for Sender<T>
  • impl<T> Clone for Sender<T>

ReceiverSource

pub struct Receiver<T>

The receiving end.

  • pub const fn recv_async(self) -> RecvFuture<T>§

    Source

    await rx.recv_async() inside async code: like recv, but suspends the task instead of blocking the thread.

  • pub fn recv(self) -> T | none§

    Source

    The next value, blocking until one arrives; none once the queue is empty and every sender has closed.

  • pub fn try_recv(self) -> T | Empty | Closed§

    Source

    The next value if one is queued, else whether a sender may still send one (Empty) or every sender has closed (Closed).

  • pub fn iter(self) -> ReceiverIter<T>§

    Source

    Values until the channel closes (also for v in rx).

Trait implementations 3

ReceiverIterSource

pub struct ReceiverIter<T>

The iterator for x in rx walks: each item is a blocking recv; it ends when the channel is closed and drained.

Trait implementations 2
  • impl<T> Debug for ReceiverIter<T>
  • impl<T> Iterator for ReceiverIter<T>

RecvFutureSource

pub struct RecvFuture<T>

Receiver::recv_async.

Trait implementations 2
  • impl<T> Debug for RecvFuture<T>
  • impl<T> core::future::Future for RecvFuture<T>

SendFutureSource

pub struct SendFuture<T>

Sender::send_async.

  • pub fn poll(ref self, ref ctx: core::future::Context) throws (SendError<T>) -> core::future::Poll<()>§

    Source

    One step of an async send: Ready(()) once the value is queued, Pending while the channel is full. Throws SendError::Closed with the value when this sender was closed.

Trait implementations 1
  • impl<T> Debug for SendFuture<T>

Enums

SendErrorSource

pub enum SendError<T>

What send hands back when this sender was closed.

Trait implementations 3
  • impl<T> Display for SendError<T>
  • impl<T> Debug for SendError<T>
  • impl<T> Error for SendError<T>

TrySendErrorSource

pub enum TrySendError<T>

What try_send hands back when the value was not sent: the channel was full, or this sender was closed.

Trait implementations 3
  • impl<T> Display for TrySendError<T>
  • impl<T> Debug for TrySendError<T>
  • impl<T> Error for TrySendError<T>

Functions

channelSource

pub const fn channel<T: Send>() -> (Sender<T>, Receiver<T>)

An unbounded channel.

channel_boundedSource

pub const fn channel_bounded<T: Send>(cap: usize) -> (Sender<T>, Receiver<T>)

A channel holding at most cap queued values: send blocks while it is full. cap 0 is a rendezvous channel: send returns once a receiver has taken the value.