Struct tracing::dispatch::WeakDispatch
source · pub struct WeakDispatch { /* private fields */ }
Expand description
WeakDispatch
is a version of Dispatch
that holds a non-owning reference
to a collector.
The collector may be accessed by calling WeakDispatch::upgrade
,
which returns an Option<Dispatch>
. If all Dispatch
clones that point
at the collector have been dropped, WeakDispatch::upgrade
will return
None
. Otherwise, it will return Some(Dispatch)
.
A WeakDispatch
may be created from a Dispatch
by calling the
Dispatch::downgrade
method. The primary use for creating a
WeakDispatch
is to allow a collector 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 a
Dispatch
rather than an Arc
.
Implementations§
source§impl WeakDispatch
impl WeakDispatch
sourcepub fn upgrade(&self) -> Option<Dispatch>
pub fn upgrade(&self) -> Option<Dispatch>
Attempts to upgrade this WeakDispatch
to a Dispatch
.
Returns None
if the referenced Dispatch
has already been dropped.
§Examples
static COLLECTOR: NoCollector = NoCollector::new();
let strong = Dispatch::new(COLLECTOR);
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());
Trait Implementations§
source§impl Clone for WeakDispatch
impl Clone for WeakDispatch
source§fn clone(&self) -> WeakDispatch
fn clone(&self) -> WeakDispatch
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more