Struct Sender
pub struct Sender<T> { /* private fields */ }
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, 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 aoneshotchannel 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(&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) -> 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(&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
Trait Implementations
impl<T> Drop for Sender<T>
fn drop(&mut self)
impl<T: Debug> Debug for Sender<T>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Auto Trait Implementations
impl<T> !RefUnwindSafe for Sender<T>
impl<T> !UnwindSafe for Sender<T>
impl<T> Freeze for Sender<T>
where
Option<Arc<Inner<T>>>: Freeze,
impl<T> Send for Sender<T>
where
Option<Arc<Inner<T>>>: Send,
impl<T> Sync for Sender<T>
where
Option<Arc<Inner<T>>>: Sync,
impl<T> Unpin for Sender<T>
where
Option<Arc<Inner<T>>>: Unpin,
impl<T> UnsafeUnpin for Sender<T>
where
Option<Arc<Inner<T>>>: UnsafeUnpin,
Blanket Implementations
impl<T> Any for Sender<T>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Sender<T>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Sender<T>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for Sender<T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into<U> for Sender<T>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Sender<T>
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Sender<T>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>