Skip to content

Commit

Permalink
tracing: impl From<EnteredSpan> for Option<Id>
Browse files Browse the repository at this point in the history
  • Loading branch information
Folyd committed Mar 30, 2021
1 parent 8f18633 commit 098bc35
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tracing/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,18 @@ impl<'a> From<&'a Span> for Option<Id> {
}
}

impl<'a> From<&'a EnteredSpan> for Option<&'a Id> {
fn from(span: &'a EnteredSpan) -> Self {
span.inner.as_ref().map(|inner| &inner.id)
}
}

impl<'a> From<&'a EnteredSpan> for Option<Id> {
fn from(span: &'a EnteredSpan) -> Self {
span.inner.as_ref().map(Inner::id)
}
}

impl Drop for Span {
fn drop(&mut self) {
if let Some(Inner {
Expand Down Expand Up @@ -1394,6 +1406,11 @@ impl Clone for Inner {
// ===== impl Entered =====

impl EnteredSpan {
/// Returns this span's `Id`, if it is enabled.
pub fn id(&self) -> Option<Id> {
self.inner.as_ref().map(Inner::id)
}

/// Exits this span, returning the underlying [`Span`].
#[inline]
pub fn exit(mut self) -> Span {
Expand Down Expand Up @@ -1445,6 +1462,7 @@ impl Drop for EnteredSpan {
struct PhantomNotSend {
ghost: PhantomData<*mut ()>,
}

#[allow(non_upper_case_globals)]
const PhantomNotSend: PhantomNotSend = PhantomNotSend { ghost: PhantomData };

Expand Down

0 comments on commit 098bc35

Please sign in to comment.