Struct Sender
struct Sender<T> { ... }
Sends a value to the associated Receiver.
A pair of both a Sender and a Receiver are created by the
channel function.
Examples
use oneshot;
async
If the sender is dropped without sending, the receiver will fail with
[error::RecvError]:
use oneshot;
async
To use a Sender from a destructor, put it in an Option and call
Option::take.
use oneshot;
# async
#
async
Implementations
impl<T> Sender<T>
fn send(self: Self, t: T) -> Result<(), T>Attempts to send a value on this channel, returning it back if it could not be sent.
This method consumes
selfas only one value may ever be sent on aoneshotchannel. It is not marked async because sending a message to anoneshotchannel never requires any form of waiting. Because of this, thesendmethod can be used in both synchronous and asynchronous code without problems.A successful send occurs when it is determined that the other end of the channel has not hung up already. An unsuccessful send would be one where the corresponding receiver has already been deallocated. Note that a return value of
Errmeans that the data will never be received, but a return value ofOkdoes not mean that the data will be received. It is possible for the corresponding receiver to hang up immediately after this function returnsOk.Examples
Send a value to another task
use oneshot; asyncasync fn closed(self: &mut Self)Waits for the associated
Receiverhandle to close.A
Receiveris closed by either callingcloseexplicitly or theReceivervalue is dropped.This function is useful when paired with
select!to abort a computation when the receiver is no longer interested in the result.Return
Returns a
Futurewhich must be awaited on.Examples
Basic usage
use oneshot; asyncPaired with select
use oneshot; use ; async asyncfn is_closed(self: &Self) -> boolReturns
trueif the associatedReceiverhandle has been dropped.A
Receiveris closed by either callingcloseexplicitly or theReceivervalue is dropped.If
trueis returned, a call tosendwill always result in an error.Examples
use oneshot; asyncfn poll_closed(self: &mut Self, cx: &mut Context<'_>) -> Poll<()>Checks whether the
oneshotchannel has been closed, and if not, schedules theWakerin the providedContextto receive a notification when the channel is closed.A
Receiveris closed by either callingcloseexplicitly, or when theReceivervalue is dropped.Note that on multiple calls to poll, only the
Wakerfrom theContextpassed to the most recent call will be scheduled to receive a wakeup.Return value
This function returns:
Poll::Pendingif the channel is still open.Poll::Ready(())if the channel is closed.
Examples
use oneshot; use poll_fn; async
impl<T> Any for Sender<T>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Sender<T>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Sender<T>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> Drop for Sender<T>
fn drop(self: &mut Self)
impl<T> Freeze for Sender<T>
impl<T> From for Sender<T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> RefUnwindSafe for Sender<T>
impl<T> Send for Sender<T>
impl<T> Sync for Sender<T>
impl<T> Unpin for Sender<T>
impl<T> UnwindSafe for Sender<T>
impl<T, U> Into for Sender<T>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Sender<T>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Sender<T>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>
impl<T: $crate::fmt::Debug> Debug for Sender<T>
fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result