Skip to content

Commit

Permalink
clarify WeakDispatch::upgrade docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jswrenn committed Sep 20, 2022
1 parent 674357d commit d50d6f8
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tracing-core/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,25 @@ where
}

impl WeakDispatch {
/// Attempts to upgrade the `WeakDispatch` to a `Dispatch`.
/// Attempts to upgrade the `WeakDispatch` to a [`Dispatch`].
///
/// Returns `None` if the inner `Dispatch` has already been dropped.
///
/// ## Examples
///
/// ```
/// # use tracing_core::collect::NoCollector;
/// # use tracing_core::dispatch::Dispatch;
/// 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());
/// ```
pub fn upgrade(&self) -> Option<Dispatch> {
#[cfg(feature = "alloc")]
let collector = match &self.collector {
Expand Down

0 comments on commit d50d6f8

Please sign in to comment.