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.
Trait Implementations§
impl<T: ?Sized + Send + Sync> Send for Weak<T>
impl<T: ?Sized + Send + Sync> Sync for Weak<T>
Auto Trait Implementations§
impl<T: ?Sized> RefUnwindSafe for Weak<T>where
T: RefUnwindSafe,
impl<T: ?Sized> Unpin for Weak<T>
impl<T: ?Sized> UnwindSafe for Weak<T>where
T: RefUnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more