pub struct Sender<T> { /* private fields */ }🔬This is a nightly-only experimental API. (
oneshot_channel)Expand description
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§
Source§impl<T> Sender<T>
impl<T> Sender<T>
Sourcepub fn send(self, t: T) -> Result<(), SendError<T>>
🔬This is a nightly-only experimental API. (oneshot_channel)
pub fn send(self, t: T) -> Result<(), SendError<T>>
oneshot_channel)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§
Auto Trait Implementations§
impl<T> Freeze for Sender<T>
impl<T> RefUnwindSafe for Sender<T>
impl<T> Send for Sender<T>where
T: Send,
impl<T> Unpin for Sender<T>
impl<T> UnsafeUnpin for Sender<T>
impl<T> UnwindSafe for Sender<T>
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Gets the layout of the type.