[−][src]Struct refptr::WeakPtr
Weak reference to a Refcounted
object.
Weak pointers can only be used on objects which have refcounts supporting weak references.
Example
#[refcounted(atomic, weak)] struct HeapInt { i: i32 } let here = make_refptr!(HeapInt { i: 10 }); let weak = WeakPtr::new(&*here); assert_eq!(weak.upgrade().unwrap().i, 10); drop(here); assert!(weak.upgrade().is_none());
Implementations
impl<T: ?Sized> WeakPtr<T> where
T: Refcounted,
T::Rc: WeakRefcount,
[src]
T: Refcounted,
T::Rc: WeakRefcount,
pub fn new(val: &T) -> WeakPtr<T>
[src]
Obtain a new weak reference to a refcounted object.
pub fn upgrade(&self) -> Option<RefPtr<T>>
[src]
Attempt to upgrade this weak reference into a strong reference, returning it.
pub fn strong_count(&self) -> usize
[src]
Gets the number of strong references to this allocation.
pub fn weak_count(&self) -> usize
[src]
Gets the number of weak references to this allocation.
If there are no remaining strong references, this will
return 0
.
Trait Implementations
impl<T: ?Sized> Clone for WeakPtr<T> where
T: Refcounted,
T::Rc: WeakRefcount,
[src]
T: Refcounted,
T::Rc: WeakRefcount,
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: ?Sized> Debug for WeakPtr<T> where
T: Refcounted,
T::Rc: WeakRefcount,
[src]
T: Refcounted,
T::Rc: WeakRefcount,
impl<T: ?Sized> Drop for WeakPtr<T> where
T: Refcounted,
T::Rc: WeakRefcount,
[src]
T: Refcounted,
T::Rc: WeakRefcount,
impl<T: ?Sized> Send for WeakPtr<T> where
T: Refcounted + Send + Sync,
T::Rc: WeakRefcount,
[src]
T: Refcounted + Send + Sync,
T::Rc: WeakRefcount,
impl<T: ?Sized> Sync for WeakPtr<T> where
T: Refcounted + Send + Sync,
T::Rc: WeakRefcount,
[src]
T: Refcounted + Send + Sync,
T::Rc: WeakRefcount,
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,