当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Rust Arc.weak_count用法及代码示例


本文简要介绍rust语言中 alloc::sync::Arc.weak_count 的用法。

用法

pub fn weak_count(this: &Self) -> usize

获取指向此分配的 Weak 指针的数量。

安全性

这种方法本身是安全的,但正确使用它需要格外小心。另一个线程可以随时更改弱计数,包括可能在调用此方法和对结果进行操作之间。

例子

use std::sync::Arc;

let five = Arc::new(5);
let _weak_five = Arc::downgrade(&five);

// This assertion is deterministic because we haven't shared
// the `Arc` or `Weak` between threads.
assert_eq!(1, Arc::weak_count(&five));

相关用法


注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 alloc::sync::Arc.weak_count。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。