WeakDispatch in tracing_core::dispatcher - Rust (original) (raw)

Struct WeakDispatch

Source

pub struct WeakDispatch { /* private fields */ }

Expand description

WeakDispatch is a version of Dispatch that holds a non-owning reference to a Subscriber.

The Subscriber may be accessed by calling [WeakDispatch::upgrade], which returns an Option. If all [Dispatch] clones that point at the Subscriber have been dropped, [WeakDispatch::upgrade] will return None. Otherwise, it will return Some(Dispatch)`.

A WeakDispatch may be created from a Dispatch by calling theDispatch::downgrade method. The primary use for creating aWeakDispatch is to allow a Subscriber` to hold a cyclical reference to itself without creating a memory leak. See here for details.

This type is analogous to the std::sync::Weak type, but for aDispatch rather than an Arc.

Source§

Source

Attempts to upgrade this WeakDispatch to a Dispatch.

Returns None if the referenced Dispatch has already been dropped.

§Examples
let strong = Dispatch::new(NoSubscriber::default());
let weak = strong.downgrade();

// The strong here keeps it alive, so we can still access the object.
assert!(weak.upgrade().is_some());

drop(strong); // But not any more.
assert!(weak.upgrade().is_none());

§

§

§

§

§

§