跳到主要内容

WeakUnboundedSender

搜索

结构体 WeakUnboundedSender 

Source
pub struct WeakUnboundedSender<T> { /* private fields */ }
展开描述

一个无界 sender,不会阻止 channel 被关闭。

如果通道的所有 UnboundedSender 实例 都已被丢弃, 且仅剩 WeakUnboundedSender 实例, 则该通道 被关闭。

为了发送消息, WeakUnboundedSender 需要使用 WeakUnboundedSender::upgrade 进行升级, 它返回 Option<UnboundedSender>。 如果所有 UnboundedSender 都已被丢弃, 则返回 None, 否则返回一个 UnboundedSender

§示例

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

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());

实现§

Source§

impl<T> WeakUnboundedSender<T>

Source

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

尝试将 WeakUnboundedSender 转换为 UnboundedSender。如果还有其他 Sender 实例处于活动状态且通道先前未被丢弃,则返回 Some,否则返回 None。

Source

pub fn strong_count(&self) -> usize

返回 UnboundedSender 句柄的数量。

Source

pub fn weak_count(&self) -> usize

返回 WeakUnboundedSender 句柄的数量。

Trait 实现§

Source§

impl<T> Clone for WeakUnboundedSender<T>

Source§

fn clone(&self) -> Self

返回值的副本。 更多信息
1.0.0 · Source§

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

Performs copy-assignment from source. 更多信息
Source§

impl<T> Debug for WeakUnboundedSender<T>

Source§

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

使用给定的格式化器格式化此值。 更多信息
Source§

impl<T> Drop for WeakUnboundedSender<T>

Source§

fn drop(&mut self)

执行此类型的析构函数。 更多信息

自动 Trait 实现§

Blanket 实现§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. 更多信息
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. 更多信息
Source§

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

Source§

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

Mutably borrows from an owned value. 更多信息
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. 更多信息
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

原样返回传入的参数。

Source§

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

Source§

fn into(self) -> U

调用 U::from(self)

也就是说,此转换的具体行为取决于 From<T> for U 的实现方式。

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

获得所有权后的类型。
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. 更多信息
Source§

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

Uses borrowed data to replace owned data, usually by cloning. 更多信息
Source§

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

Source§

type Error = Infallible

转换出错时返回的类型。
Source§

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

执行转换。
Source§

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

Source§

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

转换出错时返回的类型。
Source§

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

执行转换。