Struct WeakDispatch
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 the
Dispatch::downgrade
method. The primary use for creating a
WeakDispatch
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 a
Dispatch
rather than an Arc
.
Implementations§
§impl WeakDispatch
impl WeakDispatch
pub 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
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());
Trait Implementations§
§impl Clone for WeakDispatch
impl Clone for WeakDispatch
§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 moreAuto Trait Implementations§
impl Freeze for WeakDispatch
impl !RefUnwindSafe for WeakDispatch
impl Send for WeakDispatch
impl Sync for WeakDispatch
impl Unpin for WeakDispatch
impl !UnwindSafe for WeakDispatch
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
std
only.Source§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
std
only.