Receiver

Struct Receiver 

Source
pub struct Receiver<S: OneshotStorage> { /* private fields */ }
Expand description

Receiver for one-shot value transfer

Implements Future directly for .await usage.

一次性值传递的接收器

直接实现了 Future,可直接使用 .await

Implementations§

Source§

impl<S: OneshotStorage> Receiver<S>

Source

pub async fn wait(self) -> Result<S::Value, RecvError>

Wait for value asynchronously

Source

pub fn close(&mut self)

Close the receiver, preventing any future messages from being sent.

Any send operation which happens after this method returns is guaranteed to fail. After calling close, try_recv should be called to receive a value if one was sent before the call to close completed.

关闭接收器,阻止任何将来的消息发送。

在此方法返回后发生的任何 send 操作都保证失败。 调用 close 后,应调用 try_recv 来接收在 close 完成之前发送的值。

Source

pub fn blocking_recv(self) -> Result<S::Value, RecvError>

Blocking receive, waiting for a value to be sent.

This method is intended for use in synchronous code.

§Panics

This function panics if called within an asynchronous execution context.

阻塞接收,等待值被发送。

此方法用于同步代码中。

§Panics

如果在异步执行上下文中调用此函数,则会 panic。

Source§

impl<T: Send> Receiver<GenericStorage<T>>

Source

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

Try to receive a value without blocking

Returns Ok(value) if value is ready, Err(TryRecvError::Empty) if pending, or Err(TryRecvError::Closed) if sender was dropped.

尝试接收值而不阻塞

如果值就绪返回 Ok(value),如果待处理返回 Err(TryRecvError::Empty), 如果发送器被丢弃返回 Err(TryRecvError::Closed)

Source§

impl<S: State> Receiver<LiteStorage<S>>

Source

pub async fn recv(self) -> Result<S, RecvError>

Receive a value asynchronously

This is equivalent to using .await directly on the receiver

异步接收一个值

这等同于直接在 receiver 上使用 .await

Source

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

Try to receive a value without blocking

Returns Ok(value) if value is ready, Err(TryRecvError::Empty) if pending, or Err(TryRecvError::Closed) if sender was dropped.

尝试接收值而不阻塞

如果值就绪返回 Ok(value),如果待处理返回 Err(TryRecvError::Empty), 如果发送器被丢弃返回 Err(TryRecvError::Closed)

Trait Implementations§

Source§

impl<S: OneshotStorage> Debug for Receiver<S>

Source§

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

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

impl<S: OneshotStorage> Future for Receiver<S>

Source§

type Output = Result<<S as OneshotStorage>::Value, RecvError>

The type of value produced on completion.
Source§

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>

Attempts to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more
Source§

impl<S: OneshotStorage> Unpin for Receiver<S>

Auto Trait Implementations§

§

impl<S> Freeze for Receiver<S>

§

impl<S> !RefUnwindSafe for Receiver<S>

§

impl<S> Send for Receiver<S>

§

impl<S> Sync for Receiver<S>

§

impl<S> !UnwindSafe for Receiver<S>

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> 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<F> IntoFuture for F
where F: Future,

Source§

type Output = <F as Future>::Output

The output that the future will produce on completion.
Source§

type IntoFuture = F

Which kind of future are we turning this into?
Source§

fn into_future(self) -> <F as IntoFuture>::IntoFuture

Creates a future from a value. 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.