pub struct WeakCell<T>(/* private fields */);
Expand description
Version of RefCell
that holds a non-owning reference to the managed allocation.
Implementations§
Source§impl<T> WeakCell<T>
impl<T> WeakCell<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Constructs a new WeakCell<T>
, without allocating any memory.
Calling WeakCell::upgrade on the return value always gives None.
§Examples
use rccell::WeakCell;
let empty: WeakCell<i32> = WeakCell::new();
assert!(empty.upgrade().is_none());
Sourcepub fn upgrade(&self) -> Option<RcCell<T>>
pub fn upgrade(&self) -> Option<RcCell<T>>
Similar to Weak::upgrade.
Attempts to upgrade the WeakCell
pointer to an RcCell
.
Returns None
if the inner value has been dropped.
§Examples
use rccell::RcCell;
let five = RcCell::new(5);
let weak_five = five.downgrade();
let strong_five = weak_five.upgrade();
assert!(strong_five.is_some());
drop(strong_five);
drop(five);
assert!(weak_five.upgrade().is_none());
Sourcepub fn strong_count(&self) -> usize
pub fn strong_count(&self) -> usize
Gets the number of strong (RcCell
) pointers pointing to this allocation.
If self
was created using WeakCell::new, this will return 0.
Sourcepub fn weak_count(&self) -> usize
pub fn weak_count(&self) -> usize
Gets the number of WeakCell
pointers pointing to this allocation.
If no strong pointers remain, this will return 0.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for WeakCell<T>
impl<T> !RefUnwindSafe for WeakCell<T>
impl<T> !Send for WeakCell<T>
impl<T> !Sync for WeakCell<T>
impl<T> Unpin for WeakCell<T>
impl<T> !UnwindSafe for WeakCell<T>
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