Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tracing: impl From<EnteredSpan> for Option<Id> #1325

Merged
merged 4 commits into from
Apr 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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