Struct Sender

pub struct Sender<T> { pub(in ::sync::oneshot) inner: 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();

Fields

inner: Sender<T>

The oneshot channel is simply a wrapper around a mpmc channel.

Implementations

impl<T> Sender<T>

fn send(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);

Trait Implementations

impl<T> Debug for Sender<T>

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

impl<T> Sync for Sender<T>

Auto Trait Implementations

impl<T> Freeze for Sender<T> where Sender<T>: Freeze,

impl<T> RefUnwindSafe for Sender<T> where Sender<T>: RefUnwindSafe,

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

impl<T> Unpin for Sender<T> where Sender<T>: Unpin,

impl<T> UnsafeUnpin for Sender<T> where Sender<T>: UnsafeUnpin,

impl<T> UnwindSafe for Sender<T> where Sender<T>: UnwindSafe,

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) -> T

Returns the argument unchanged.

impl<T> SizeHint for Sender<T> where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for Sender<T>

impl<T, U> Into<U> for Sender<T> where U: From<T>,

fn into(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<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>