From 876fe1ff92fafa835f3a82c1a10dded02f59e3a0 Mon Sep 17 00:00:00 2001 From: Jack Wrenn Date: Tue, 26 Jul 2022 18:24:01 -0400 Subject: [PATCH] subscriber: impl `LookupSpan` for `Box` and `Arc` (#2247) These implementations mirror those provided by tracing-core for `Collect` on `Box` and `Arc`. --- tracing-subscriber/src/registry/mod.rs | 65 +++++++++++++++++++++++++ tracing-subscriber/src/subscribe/mod.rs | 2 +- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/tracing-subscriber/src/registry/mod.rs b/tracing-subscriber/src/registry/mod.rs index 6ee7ebba44..48b378d1ed 100644 --- a/tracing-subscriber/src/registry/mod.rs +++ b/tracing-subscriber/src/registry/mod.rs @@ -235,6 +235,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}; use core::{fmt,iter}; @@ -255,6 +260,66 @@ feature! { #[cfg(feature = "smallvec")] type SpanRefVecArray<'span, L> = [SpanRef<'span, L>; 16]; + impl<'a, S> LookupSpan<'a> for Arc + where + S: LookupSpan<'a>, + { + type Data = >::Data; + + fn span_data(&'a self, id: &Id) -> Option { + self.as_ref().span_data(id) + } + + fn span(&'a self, id: &Id) -> Option> + 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 + where + S: LookupSpan<'a>, + { + type Data = >::Data; + + fn span_data(&'a self, id: &Id) -> Option { + self.as_ref().span_data(id) + } + + fn span(&'a self, id: &Id) -> Option> + 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>, diff --git a/tracing-subscriber/src/subscribe/mod.rs b/tracing-subscriber/src/subscribe/mod.rs index 6c1878b177..47bec36028 100644 --- a/tracing-subscriber/src/subscribe/mod.rs +++ b/tracing-subscriber/src/subscribe/mod.rs @@ -1656,7 +1656,7 @@ feature! { } - impl Subscribe for Vec + impl Subscribe for alloc::vec::Vec where S: Subscribe, C: Collect,