Struct WeakUnboundedSender

struct WeakUnboundedSender<T> { ... }

An unbounded sender that does not prevent the channel from being closed.

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

In order to send messages, the WeakUnboundedSender needs to be upgraded using WeakUnboundedSender::upgrade, which returns Option<UnboundedSender>. It returns None if all UnboundedSenders have been dropped, and otherwise it returns an UnboundedSender.

Examples

use tokio::sync::mpsc::unbounded_channel;

#[tokio::main]
async fn main() {
    let (tx, _rx) = unbounded_channel::<i32>();
    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> WeakUnboundedSender<T>

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

Tries to convert a WeakUnboundedSender into an UnboundedSender. 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 UnboundedSender handles.

fn weak_count(self: &Self) -> usize

Returns the number of WeakUnboundedSender handles.

impl<T> Any for WeakUnboundedSender<T>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for WeakUnboundedSender<T>

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

impl<T> BorrowMut for WeakUnboundedSender<T>

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

impl<T> Clone for WeakUnboundedSender<T>

fn clone(self: &Self) -> Self

impl<T> CloneToUninit for WeakUnboundedSender<T>

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

impl<T> Debug for WeakUnboundedSender<T>

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

impl<T> Drop for WeakUnboundedSender<T>

fn drop(self: &mut Self)

impl<T> Freeze for WeakUnboundedSender<T>

impl<T> From for WeakUnboundedSender<T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> RefUnwindSafe for WeakUnboundedSender<T>

impl<T> Send for WeakUnboundedSender<T>

impl<T> Sync for WeakUnboundedSender<T>

impl<T> ToOwned for WeakUnboundedSender<T>

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

impl<T> Unpin for WeakUnboundedSender<T>

impl<T> UnsafeUnpin for WeakUnboundedSender<T>

impl<T> UnwindSafe for WeakUnboundedSender<T>

impl<T, U> Into for WeakUnboundedSender<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 WeakUnboundedSender<T>

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

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

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