Struct Sender

struct Sender<T> { ... }

The sending half of a oneshot channel.

Examples

#![feature(oneshot_channel)]
use std::sync::oneshot;
use std::thread;

let (sender, receiver) = oneshot::channel();

thread::spawn(move || {
    sender.send("Hello from thread!").unwrap();
});

assert_eq!(receiver.recv().unwrap(), "Hello from thread!");

Sender cannot be sent between threads if it is sending non-Send types.

#![feature(oneshot_channel)]
use std::sync::oneshot;
use std::thread;
use std::ptr;

let (sender, receiver) = oneshot::channel();

struct NotSend(*mut ());
thread::spawn(move || {
    sender.send(NotSend(ptr::null_mut()));
});

let reply = receiver.try_recv().unwrap();

Implementations

impl<T> Sender<T>

fn send(self: Self, t: T) -> Result<(), SendError<T>>

Attempts to send a value through this channel. This can only fail if the corresponding [Receiver<T>] has been dropped.

This method is non-blocking (wait-free).

Examples

#![feature(oneshot_channel)]
use std::sync::oneshot;
use std::thread;

let (tx, rx) = oneshot::channel();

thread::spawn(move || {
    // Perform some computation.
    let result = 2 + 2;
    tx.send(result).unwrap();
});

assert_eq!(rx.recv().unwrap(), 4);

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> Debug for Sender<T>

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

impl<T> Freeze for Sender<T>

impl<T> From for Sender<T>

fn from(t: T) -> T

Returns 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) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses 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>