[][src]Struct refptr::WeakPtr

pub struct WeakPtr<T: ?Sized> where
    T: Refcounted,
    T::Rc: WeakRefcount
{ /* fields omitted */ }

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]

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]

impl<T: ?Sized> Debug for WeakPtr<T> where
    T: Refcounted,
    T::Rc: WeakRefcount
[src]

impl<T: ?Sized> Drop for WeakPtr<T> where
    T: Refcounted,
    T::Rc: WeakRefcount
[src]

impl<T: ?Sized> Send for WeakPtr<T> where
    T: Refcounted + Send + Sync,
    T::Rc: WeakRefcount
[src]

impl<T: ?Sized> Sync for WeakPtr<T> where
    T: Refcounted + Send + Sync,
    T::Rc: WeakRefcount
[src]

Auto Trait Implementations

impl<T: ?Sized> Unpin for WeakPtr<T> where
    T: Unpin

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.