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
`Collect` on `Box<C>` and `Arc<C>`.
  • Loading branch information
jswrenn authored and hawkw committed Jul 29, 2022
1 parent d2ad8ab commit b724b20
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tracing-subscriber/src/layer/mod.rs
Expand Up @@ -1569,7 +1569,7 @@ where
feature! {
#![any(feature = "std", feature = "alloc")]
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use alloc::{vec::Vec, boxed::Box};

macro_rules! layer_impl_body {
() => {
Expand Down
65 changes: 65 additions & 0 deletions tracing-subscriber/src/registry/mod.rs
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 b724b20

Please sign in to comment.