Struct WeakSender

struct WeakSender<T> { ... }

A sender that does not prevent the channel from being closed.

If all Sender instances of a channel were dropped and only WeakSender instances remain, the channel is closed.

In order to send messages, the WeakSender needs to be upgraded using WeakSender::upgrade, which returns Option<Sender>. It returns None if all Senders have been dropped, and otherwise it returns a Sender.

Examples

use tokio::sync::broadcast::channel;

#[tokio::main]
async fn main() {
    let (tx, _rx) = channel::<i32>(15);
    let tx_weak = tx.downgrade();

    // Upgrading will succeed because `tx` still exists.
    assert!(tx_weak.upgrade().is_some());

    // If we drop `tx`, then it will fail.
    drop(tx);
    assert!(tx_weak.clone().upgrade().is_none());
}

Implementations

impl<T> WeakSender<T>

fn upgrade(self: &Self) -> Option<Sender<T>>

Tries to convert a WeakSender into a Sender.

This will return Some if there are other Sender instances alive and the channel wasn't previously dropped, otherwise None is returned.

fn strong_count(self: &Self) -> usize

Returns the number of Sender handles.

fn weak_count(self: &Self) -> usize

Returns the number of WeakSender handles.

impl<T> Any for WeakSender<T>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for WeakSender<T>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for WeakSender<T>

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

impl<T> Clone for WeakSender<T>

fn clone(self: &Self) -> WeakSender<T>

impl<T> CloneToUninit for WeakSender<T>

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

impl<T> Debug for WeakSender<T>

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

impl<T> Drop for WeakSender<T>

fn drop(self: &mut Self)

impl<T> Freeze for WeakSender<T>

impl<T> From for WeakSender<T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> RefUnwindSafe for WeakSender<T>

impl<T> Send for WeakSender<T>

impl<T> Sync for WeakSender<T>

impl<T> ToOwned for WeakSender<T>

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> Unpin for WeakSender<T>

impl<T> UnwindSafe for WeakSender<T>

impl<T, U> Into for WeakSender<T>

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for WeakSender<T>

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

impl<T, U> TryInto for WeakSender<T>

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