Struct WeakDispatch

pub struct WeakDispatch { /* private fields */ }

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) -> 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());

Trait Implementations

impl Clone for WeakDispatch

fn clone(&self) -> WeakDispatch

impl Debug for WeakDispatch

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

Auto Trait Implementations

impl !RefUnwindSafe for WeakDispatch

impl !UnwindSafe for WeakDispatch

impl Freeze for WeakDispatch

impl Send for WeakDispatch

impl Sync for WeakDispatch

impl Unpin for WeakDispatch

impl UnsafeUnpin for WeakDispatch

Blanket Implementations

impl<T> Any for WeakDispatch where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for WeakDispatch where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for WeakDispatch where T: ?Sized,

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

impl<T> CloneToUninit for WeakDispatch where T: Clone,

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

impl<T> From<T> for WeakDispatch

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for WeakDispatch where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for WeakDispatch where U: From<T>,

fn into(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<U> for WeakDispatch where U: Into<T>,

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

impl<T, U> TryInto<U> for WeakDispatch where U: TryFrom<T>,

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