Struct portable_atomic_util::Weak
source · pub struct Weak<T: ?Sized> { /* private fields */ }Available on crate features
alloc or std only.Expand description
A weakly reference counted pointer.
This is an equivalent to std::sync::Weak, but using portable-atomic for synchronization.
See the documentation for the standard library’s Weak for more details.
Examples
use portable_atomic_util::Arc;
use std::thread;
let five = Arc::new(5);
let weak_five = Arc::downgrade(&five);
thread::spawn(move || {
let five = weak_five.upgrade().unwrap();
assert_eq!(*five, 5);
});Implementations§
source§impl<T: ?Sized> Weak<T>
impl<T: ?Sized> Weak<T>
sourcepub fn upgrade(&self) -> Option<Arc<T>>
pub fn upgrade(&self) -> Option<Arc<T>>
Try to upgrade this Weak pointer to a strong pointer.
Example
use portable_atomic_util::Arc;
let five = Arc::new(5);
let weak = Arc::downgrade(&five);
assert!(weak.upgrade().is_some());sourcepub fn strong_count(&self) -> usize
pub fn strong_count(&self) -> usize
Get the number of strong pointers to this allocation.
sourcepub fn weak_count(&self) -> usize
pub fn weak_count(&self) -> usize
Get the number of weak pointers to this allocation.