Skip to main content

WeakRef

Trait WeakRef 

Source
pub trait WeakRef {
    type Strong: StrongRef<Weak = Self>;

    // Required method
    fn upgrade(&self) -> Option<Self::Strong>;

    // Provided method
    fn is_expired(&self) -> bool { ... }
}
Expand description

A trait for weak references.

Required Associated Types§

Source

type Strong: StrongRef<Weak = Self>

The type of the strong reference.

For example, for std::rc::Weak<T>, this will be std::rc::Rc<T>.

Required Methods§

Source

fn upgrade(&self) -> Option<Self::Strong>

Acquires a strong reference from a weak reference.

This is usually implemented by an upgrade method.

Provided Methods§

Source

fn is_expired(&self) -> bool

Is the given weak element expired?

The default implemention checks whether a strong reference can be obtained via upgrade.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: ?Sized> WeakRef for Weak<T>

Source§

type Strong = Rc<T>

Source§

fn upgrade(&self) -> Option<Self::Strong>

Source§

fn is_expired(&self) -> bool

Source§

impl<T: ?Sized> WeakRef for Weak<T>

Source§

type Strong = Arc<T>

Source§

fn upgrade(&self) -> Option<Self::Strong>

Source§

fn is_expired(&self) -> bool

Implementors§