Skip to content

Commit 876fe1f

Browse files
authored
subscriber: impl LookupSpan for Box<LS> and Arc<LS> (#2247)
These implementations mirror those provided by tracing-core for `Collect` on `Box<C>` and `Arc<C>`.
1 parent 0081037 commit 876fe1f

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

tracing-subscriber/src/registry/mod.rs

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

238+
use alloc::{
239+
boxed::Box,
240+
sync::Arc
241+
};
242+
238243
#[cfg(not(feature = "smallvec"))]
239244
use alloc::vec::{self, Vec};
240245
use core::{fmt,iter};
@@ -255,6 +260,66 @@ feature! {
255260
#[cfg(feature = "smallvec")]
256261
type SpanRefVecArray<'span, L> = [SpanRef<'span, L>; 16];
257262

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

tracing-subscriber/src/subscribe/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1656,7 +1656,7 @@ feature! {
16561656
}
16571657

16581658

1659-
impl<C, S> Subscribe<C> for Vec<S>
1659+
impl<C, S> Subscribe<C> for alloc::vec::Vec<S>
16601660
where
16611661
S: Subscribe<C>,
16621662
C: Collect,

0 commit comments

Comments
 (0)