Struct WeakDispatch

struct WeakDispatch { ... }

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<Dispatch>. 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

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

Attempts to upgrade this WeakDispatch to a Dispatch.

Returns None if the referenced Dispatch has already been dropped.

Examples

# use tracing_core::subscriber::NoSubscriber;
# use tracing_core::dispatcher::Dispatch;
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());

impl Clone for WeakDispatch

fn clone(self: &Self) -> WeakDispatch

impl Debug for WeakDispatch

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl Freeze for WeakDispatch

impl RefUnwindSafe for WeakDispatch

impl Send for WeakDispatch

impl Sync for WeakDispatch

impl Unpin for WeakDispatch

impl UnsafeUnpin for WeakDispatch

impl UnwindSafe for WeakDispatch

impl<T> Any for WeakDispatch

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for WeakDispatch

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for WeakDispatch

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for WeakDispatch

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for WeakDispatch

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for WeakDispatch

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for WeakDispatch

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for WeakDispatch

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for WeakDispatch

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>