pub struct Sender<T> { /* private fields */ }Expand description
Implementations§
Source§impl<T> Sender<T>
impl<T> Sender<T>
Sourcepub fn send(self, value: T) -> Result<(), T>
pub fn send(self, value: T) -> Result<(), T>
Attempts to send a value on this channel, returning it back if it could not be sent.
A successful send occurs when it is determined that the other end of the
channel has not hung up already. An unsuccessful send would be one where
the corresponding receiver has already been deallocated. Note that a
return value of Err means that the data will never be received, but
a return value of Ok does not mean that the data will be received.
It is possible for the corresponding receiver to hang up immediately
after this function returns Ok.
This method will never block the current thread.
§Example
let (tx, rx) = sync_oneshot::channel();
std::thread::spawn(move || {
if let Err(e) = tx.send(5) {
println!("the receiver dropped");
}
});
match rx.recv() {
Ok(v) => println!("got = {:?}", v),
Err(_) => println!("the sender dropped"),
}Trait Implementations§
impl<T> Send for Sender<T>where
T: Send,
impl<T> Sync for Sender<T>where
T: Send,
Auto Trait Implementations§
impl<T> Freeze for Sender<T>
impl<T> !RefUnwindSafe for Sender<T>
impl<T> Unpin for Sender<T>
impl<T> UnsafeUnpin for Sender<T>
impl<T> !UnwindSafe for Sender<T>
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