Skip to main content

Sender

Struct Sender 

Source
pub struct Sender<T> { /* private fields */ }
Expand description

Sends a value to the associated Receiver.

This is created by the channel function. Messages can be sent using send.

Implementations§

Source§

impl<T> Sender<T>

Source

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"),
}
Source

pub fn is_closed(&self) -> bool

Returns true if the associated Receiver handle has been dropped.

A Receiver is closed by either calling close explicitly or the Receiver value is dropped. If true is returned, a call to send will always result in an error.

Trait Implementations§

Source§

impl<T: Debug> Debug for Sender<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for Sender<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

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

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.