Sender

Struct Sender 

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

Puts new messages onto the channel

Implementations§

Source§

impl<T> Sender<T>

Source

pub fn close(&self)

Closes the channel for all senders and receivers. No sender will be able to send a message once the channel has been closed. Any senders which have a send in progress but no new send operations will succeed.

Receivers will continue to be able to receive remaining messages. Once they’ve received all messages Error::Closed will be returned.

§Example
let (tx, mut rx) = channel::<u8>(2)?;
assert!(!rx.is_closed());
assert!(!tx.is_closed());
tx.close();
assert!(rx.is_closed());
assert!(tx.is_closed());
Source

pub fn is_closed(&self) -> bool

Returns true if the underlying channel has been closed.

§Example
let (tx, mut rx) = channel::<u8>(2)?;
assert!(!rx.is_closed());
tx.close();
assert!(rx.is_closed());
Source§

impl<T> Sender<T>
where T: Clone,

Source

pub fn send(&self, val: T) -> Result<(), Error>

Put a new value into the channel. This function will almost never block. The underlying implementation means that writes have to be finalised in order meaning that if thread a then b writes to the channel. Thread b will have to wait for thread a to finish as thread a was first to start. Insertion is O(1) and is a very simple operation so hopefully wont be a major issue.

§Errors
§Examples
§Example A
let (tx, mut rx) = channel(2)?;
tx.send(42)?;
let v = rx.try_recv()?;
assert_eq!(v, 42);
§Example B
let x = 42;
let (tx, mut rx) = channel(2)?;
tx.send(&x)?;
let v = rx.try_recv()?;
assert_eq!(*v, 42);
§Example C (Should not compile)
{
    let (tx, mut rx) = channel(2)?;
    let x = 42;
    tx.send(&x)?;
}
Source

pub fn subscribe(&self) -> Receiver<T>

Creates a new receiver on the same channel as this sender. The receiver will start at message id 0 meaning that it’s likely the first call will return Error::Lagged which will cause it to skip ahead and catch up with the underlying channel.

§Example
let (tx, _) = channel(2)?;
tx.send(42)?;
let mut rx = tx.subscribe();
let v = rx.try_recv()?;
assert_eq!(v, 42);

Trait Implementations§

Source§

impl<T> Clone for Sender<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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> From<Arc<Gemino<T>>> for Sender<T>

Source§

fn from(ring_buffer: Arc<Gemino<T>>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Receiver<T>> for Sender<T>

Source§

fn from(receiver: Receiver<T>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> Freeze for Sender<T>

§

impl<T> !RefUnwindSafe for Sender<T>

§

impl<T> Send for Sender<T>

§

impl<T> Sync for Sender<T>

§

impl<T> Unpin 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.