pub struct Sender<T> { /* private fields */ }
Implementations§
source§impl<T> Sender<T>
impl<T> Sender<T>
sourcepub fn send(self, message: T) -> Result<(), SendError<T>>
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.
sourcepub fn is_closed(&self) -> bool
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.
sourcepub fn into_raw(self) -> *mut ()
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.
sourcepub unsafe fn from_raw(raw: *mut ()) -> Self
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.