pub struct Sender<T> {
inner: Sender<T>,
}🔬This is a nightly-only experimental API. (
oneshot_channel #143674)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();Fields§
§inner: Sender<T>🔬This is a nightly-only experimental API. (
oneshot_channel #143674)The oneshot channel is simply a wrapper around a mpmc channel.
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 #143674)
pub fn send(self, t: T) -> Result<(), SendError<T>>
oneshot_channel #143674)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
Sourcepub fn is_closed(&self) -> bool
🔬This is a nightly-only experimental API. (oneshot_channel #143674)
pub fn is_closed(&self) -> bool
oneshot_channel #143674)Returns true if the corresponding Receiver has been dropped.
If this method returns true, send is guaranteed to return an error.
On the receiving side, Receiver::is_ready checks whether a value is available without
consuming the receiver.
A return value of false does not guarantee that a later call to send will
succeed. The receiver may be dropped immediately after this method returns.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Sender<T>
impl<T> RefUnwindSafe for Sender<T>where
Sender<T>: RefUnwindSafe,
impl<T> Send for Sender<T>
impl<T> Unpin for Sender<T>
impl<T> UnsafeUnpin for Sender<T>where
Sender<T>: UnsafeUnpin,
impl<T> UnwindSafe for Sender<T>where
Sender<T>: UnwindSafe,
Blanket Implementations§
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<T> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
🔬This is a nightly-only experimental API. (
core_io_internals)Returns a lower bound on the number of elements this container-like item
contains.
For example, an array
[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
🔬This is a nightly-only experimental API. (
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
🔬This is a nightly-only experimental API. (
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
🔬This is a nightly-only experimental API. (
ptr_alignment_type #102070)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
🔬This is a nightly-only experimental API. (
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
🔬This is a nightly-only experimental API. (
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
🔬This is a nightly-only experimental API. (
sized_type_properties)The largest safe length for a
[Self]. Read more