pub struct Sender<T> {
pub(crate) channel_ptr: NonNull<Channel<T>>,
pub(crate) _invariant: PhantomData<fn(_: T) -> T>,
}
Fields§
§channel_ptr: NonNull<Channel<T>>
§_invariant: PhantomData<fn(_: T) -> T>
Implementations§
§impl<T> Sender<T>
impl<T> Sender<T>
pub 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.
pub 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.
pub unsafe fn from_raw(raw: *mut ()) -> Sender<T>
pub unsafe fn from_raw(raw: *mut ()) -> Sender<T>
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.