Skip to content

Commit a0824d3

Browse files
jswrennhawkw
authored andcommitted
subscriber: impl LookupSpan for Box<LS> and Arc<LS> (#2247)
These implementations mirror those provided by tracing-core for `Subscriber` on `Box<S>` and `Arc<S>`.
1 parent d2ad8ab commit a0824d3

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

tracing-subscriber/src/layer/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ use core::any::TypeId;
685685

686686
feature! {
687687
#![feature = "alloc"]
688-
use alloc::boxed::Box;
688+
use alloc::{vec::Vec, boxed::Box};
689689
use core::ops::{Deref, DerefMut};
690690
}
691691

@@ -1568,8 +1568,6 @@ where
15681568

15691569
feature! {
15701570
#![any(feature = "std", feature = "alloc")]
1571-
#[cfg(not(feature = "std"))]
1572-
use alloc::vec::Vec;
15731571

15741572
macro_rules! layer_impl_body {
15751573
() => {

tracing-subscriber/src/registry/mod.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ pub struct Scope<'a, R> {
230230
feature! {
231231
#![any(feature = "alloc", feature = "std")]
232232

233+
use alloc::{
234+
boxed::Box,
235+
sync::Arc
236+
};
237+
233238
#[cfg(not(feature = "smallvec"))]
234239
use alloc::vec::{self, Vec};
235240

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

259+
impl<'a, S> LookupSpan<'a> for Arc<S>
260+
where
261+
S: LookupSpan<'a>,
262+
{
263+
type Data = <S as LookupSpan<'a>>::Data;
264+
265+
fn span_data(&'a self, id: &Id) -> Option<Self::Data> {
266+
self.as_ref().span_data(id)
267+
}
268+
269+
fn span(&'a self, id: &Id) -> Option<SpanRef<'_, Self>>
270+
where
271+
Self: Sized,
272+
{
273+
self.as_ref().span(id).map(
274+
|SpanRef {
275+
registry: _,
276+
data,
277+
#[cfg(feature = "registry")]
278+
filter,
279+
}| SpanRef {
280+
registry: self,
281+
data,
282+
#[cfg(feature = "registry")]
283+
filter,
284+
},
285+
)
286+
}
287+
}
288+
289+
impl<'a, S> LookupSpan<'a> for Box<S>
290+
where
291+
S: LookupSpan<'a>,
292+
{
293+
type Data = <S as LookupSpan<'a>>::Data;
294+
295+
fn span_data(&'a self, id: &Id) -> Option<Self::Data> {
296+
self.as_ref().span_data(id)
297+
}
298+
299+
fn span(&'a self, id: &Id) -> Option<SpanRef<'_, Self>>
300+
where
301+
Self: Sized,
302+
{
303+
self.as_ref().span(id).map(
304+
|SpanRef {
305+
registry: _,
306+
data,
307+
#[cfg(feature = "registry")]
308+
filter,
309+
}| SpanRef {
310+
registry: self,
311+
data,
312+
#[cfg(feature = "registry")]
313+
filter,
314+
},
315+
)
316+
}
317+
}
318+
254319
impl<'a, R> Scope<'a, R>
255320
where
256321
R: LookupSpan<'a>,

0 commit comments

Comments
 (0)