pub struct Weak<T: ?Sized> { /* private fields */ }Available on crate feature
weak only.Expand description
A weak reference to a ThinCell that doesn’t prevent dropping.
Weak references don’t keep the value alive. The value will be dropped
when all strong references (ThinCell) are dropped, even if weak
references still exist.
Use Weak::upgrade to attempt to convert a weak reference back to a
strong reference (ThinCell). This will fail if the value has already
been dropped.
Implementations§
Source§impl<T: ?Sized> Weak<T>
impl<T: ?Sized> Weak<T>
Sourcepub fn upgrade(&self) -> Option<ThinCell<T>>
pub fn upgrade(&self) -> Option<ThinCell<T>>
Attempts to upgrade the weak reference to a strong reference.
Returns Some(ThinCell) if the value still exists, or None if it
has been dropped.
§Examples
let cell = ThinCell::new(42);
let weak = cell.downgrade();
let strong = weak.upgrade().unwrap();
assert_eq!(*strong.borrow(), 42);
drop(cell);
drop(strong);
assert!(weak.upgrade().is_none());Sourcepub fn strong_count(&self) -> usize
pub fn strong_count(&self) -> usize
Returns the number of strong references.
Sourcepub fn weak_count(&self) -> usize
pub fn weak_count(&self) -> usize
Returns the number of weak references.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Weak<T>where
T: ?Sized,
impl<T> !RefUnwindSafe for Weak<T>
impl<T> !Send for Weak<T>
impl<T> !Sync for Weak<T>
impl<T> Unpin for Weak<T>
impl<T> UnsafeUnpin for Weak<T>where
T: ?Sized,
impl<T> UnwindSafe for Weak<T>where
T: UnwindSafe + ?Sized,
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