Struct oneshot::Sender

source ·
pub struct Sender<T> { /* private fields */ }

Implementations§

source§

impl<T> Sender<T>

source

pub fn send(self, message: T) -> Result<(), SendError<T>>

Sends message over the channel to the corresponding Receiver.

Returns an error if the receiver has already been dropped. The message can be extracted from the error.

This method is lock-free and wait-free when sending on a channel that the receiver is currently not receiving on. If the receiver is receiving during the send operation this method includes waking up the thread/task. Unparking a thread involves a mutex in Rust’s standard library at the time of writing this. How lock-free waking up an async task is depends on your executor. If this method returns a SendError, please mind that dropping the error involves running any drop implementation on the message type, and freeing the channel’s heap allocation, which might or might not be lock-free.

source

pub fn is_closed(&self) -> bool

Returns true if the associated Receiver has been dropped.

If true is returned, a future call to send is guaranteed to return an error.

source

pub fn into_raw(self) -> *mut ()

Consumes the Sender, returning a raw pointer to the channel on the heap.

This is intended to simplify using oneshot channels with some FFI code. The only safe thing to do with the returned pointer is to later reconstruct the Sender with Sender::from_raw. Memory will leak if the Sender is never reconstructed.

source

pub unsafe fn from_raw(raw: *mut ()) -> Self

Consumes a raw pointer from Sender::into_raw, recreating the Sender.

§Safety

This pointer must have come from Sender<T>::into_raw with the same message type, T. At most one Sender must exist for a channel at any point in time. Constructing multiple Senders from the same raw pointer leads to undefined behavior.

Trait Implementations§

source§

impl<T: Debug> Debug for Sender<T>

source§

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

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

impl<T> Drop for Sender<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T: Send> Send for Sender<T>

Auto Trait Implementations§

§

impl<T> Freeze for Sender<T>

§

impl<T> !RefUnwindSafe for Sender<T>

§

impl<T> !Sync for Sender<T>

§

impl<T> Unpin for Sender<T>

§

impl<T> !UnwindSafe for Sender<T>

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<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.