Struct Sender
pub struct Sender<T> { /* private fields */ }
Sending-half of the broadcast channel.
May be used from many threads. Messages can be sent with
[send][Sender::send].
Examples
use broadcast;
#
# async
Implementations
impl<T> Sender<T>
fn new(capacity: usize) -> SelfCreates the sending-half of the
broadcastchannel.See the documentation of
broadcast::channelfor more information on this method.fn send(&self, value: T) -> Result<usize, SendError<T>>Attempts to send a value to all active
Receiverhandles, returning it back if it could not be sent.A successful send occurs when there is at least one active
Receiverhandle. An unsuccessful send would be one where all associatedReceiverhandles have already been dropped.Return
On success, the number of subscribed
Receiverhandles is returned. This does not mean that this number of receivers will see the message as a receiver may drop or lag (see lagging) before receiving the message.Note
A return value of
Okdoes not mean that the sent value will be observed by all or any of the activeReceiverhandles.Receiverhandles may be dropped before receiving the sent message.A return value of
Errdoes not mean that future calls tosendwill fail. NewReceiverhandles may be created by callingsubscribe.Examples
use broadcast; # # asyncfn subscribe(&self) -> Receiver<T>Creates a new
Receiverhandle that will receive values sent after this call tosubscribe.Examples
use broadcast; # # asyncfn downgrade(&self) -> WeakSender<T>Converts the
Senderto aWeakSenderthat does not count towards RAII semantics, i.e. if allSenderinstances of the channel were dropped and onlyWeakSenderinstances remain, the channel is closed.fn len(&self) -> usizeReturns the number of queued values.
A value is queued until it has either been seen by all receivers that were alive at the time it was sent, or has been evicted from the queue by subsequent sends that exceeded the queue's capacity.
Note
In contrast to
Receiver::len, this method only reports queued values and not values that have been evicted from the queue before being seen by all receivers.Examples
use broadcast; # # asyncfn is_empty(&self) -> boolReturns true if there are no queued values.
Examples
use broadcast; # # asyncfn receiver_count(&self) -> usizeReturns the number of active receivers.
An active receiver is a
Receiverhandle returned fromchannelorsubscribe. These are the handles that will receive values sent on thisSender.Note
It is not guaranteed that a sent message will reach this number of receivers. Active receivers may never call
recvagain before dropping.Examples
use broadcast; # # asyncfn same_channel(&self, other: &Self) -> boolReturns
trueif senders belong to the same channel.Examples
use broadcast; # # asyncasync fn closed(&self)A future which completes when the number of [Receiver]s subscribed to this
Senderreaches zero.Examples
use FutureExt; use broadcast; # # asyncfn strong_count(&self) -> usizeReturns the number of
Senderhandles.fn weak_count(&self) -> usizeReturns the number of
WeakSenderhandles.
Trait Implementations
impl<T> Clone for Sender<T>
fn clone(&self) -> Sender<T>
impl<T> Debug for Sender<T>
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result
impl<T> Drop for Sender<T>
fn drop(&mut self)
Auto Trait Implementations
impl<T> !RefUnwindSafe for Sender<T>
impl<T> !UnwindSafe for Sender<T>
impl<T> Freeze for Sender<T>
where
Arc<Shared<T>>: Freeze,
impl<T> Send for Sender<T>
where
Arc<Shared<T>>: Send,
impl<T> Sync for Sender<T>
where
Arc<Shared<T>>: Sync,
impl<T> Unpin for Sender<T>
where
Arc<Shared<T>>: Unpin,
impl<T> UnsafeUnpin for Sender<T>
where
Arc<Shared<T>>: UnsafeUnpin,
Blanket Implementations
impl<T> Any for Sender<T>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Sender<T>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Sender<T>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Sender<T>
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Sender<T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Sender<T>
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for Sender<T>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Sender<T>
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Sender<T>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>