Skip to content

Commit

Permalink
subscriber: impl LookupSpan for Box<LS> and Arc<LS> (#2247)
Browse files Browse the repository at this point in the history
These implementations mirror those provided by tracing-core for
`Subscriber` on `Box<S>` and `Arc<S>`.
  • Loading branch information
jswrenn authored and hawkw committed Jul 29, 2022
1 parent d2ad8ab commit a0824d3
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
4 changes: 1 addition & 3 deletions tracing-subscriber/src/layer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ use core::any::TypeId;

feature! {
#![feature = "alloc"]
use alloc::boxed::Box;
use alloc::{vec::Vec, boxed::Box};
use core::ops::{Deref, DerefMut};
}

Expand Down Expand Up @@ -1568,8 +1568,6 @@ where

feature! {
#![any(feature = "std", feature = "alloc")]
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

macro_rules! layer_impl_body {
() => {
Expand Down
65 changes: 65 additions & 0 deletions tracing-subscriber/src/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ pub struct Scope<'a, R> {
feature! {
#![any(feature = "alloc", feature = "std")]

use alloc::{
boxed::Box,
sync::Arc
};

#[cfg(not(feature = "smallvec"))]
use alloc::vec::{self, Vec};

Expand All @@ -251,6 +256,66 @@ feature! {
#[cfg(feature = "smallvec")]
type SpanRefVecArray<'span, L> = [SpanRef<'span, L>; 16];

impl<'a, S> LookupSpan<'a> for Arc<S>
where
S: LookupSpan<'a>,
{
type Data = <S as LookupSpan<'a>>::Data;

fn span_data(&'a self, id: &Id) -> Option<Self::Data> {
self.as_ref().span_data(id)
}

fn span(&'a self, id: &Id) -> Option<SpanRef<'_, Self>>
where
Self: Sized,
{
self.as_ref().span(id).map(
|SpanRef {
registry: _,
data,
#[cfg(feature = "registry")]
filter,
}| SpanRef {
registry: self,
data,
#[cfg(feature = "registry")]
filter,
},
)
}
}

impl<'a, S> LookupSpan<'a> for Box<S>
where
S: LookupSpan<'a>,
{
type Data = <S as LookupSpan<'a>>::Data;

fn span_data(&'a self, id: &Id) -> Option<Self::Data> {
self.as_ref().span_data(id)
}

fn span(&'a self, id: &Id) -> Option<SpanRef<'_, Self>>
where
Self: Sized,
{
self.as_ref().span(id).map(
|SpanRef {
registry: _,
data,
#[cfg(feature = "registry")]
filter,
}| SpanRef {
registry: self,
data,
#[cfg(feature = "registry")]
filter,
},
)
}
}

impl<'a, R> Scope<'a, R>
where
R: LookupSpan<'a>,
Expand Down

0 comments on commit a0824d3

Please sign in to comment.