Skip to content

Commit

Permalink
core: impl<C: Collect + ?Sized> Collect for Box<C>, Arc<C> (#2161)
Browse files Browse the repository at this point in the history
These broader impls supersede the previous impls where the inner type was a
`dyn Collect`. With these generic impls, you no longer must (but still can,
if you wish) cast the inner type of a boxed or arc'd collector to
`dyn Collect` to use it as a `Collect`.
  • Loading branch information
jswrenn committed Jun 16, 2022
1 parent af5edf8 commit 68bc91f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tracing-core/src/collect.rs
Expand Up @@ -654,7 +654,10 @@ impl Collect for NoCollector {
}

#[cfg(feature = "alloc")]
impl Collect for alloc::boxed::Box<dyn Collect + Send + Sync + 'static> {
impl<C> Collect for alloc::boxed::Box<C>
where
C: Collect + ?Sized,
{
#[inline]
fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest {
self.as_ref().register_callsite(metadata)
Expand Down Expand Up @@ -725,7 +728,10 @@ impl Collect for alloc::boxed::Box<dyn Collect + Send + Sync + 'static> {
}

#[cfg(feature = "alloc")]
impl Collect for alloc::sync::Arc<dyn Collect + Send + Sync + 'static> {
impl<C> Collect for alloc::sync::Arc<C>
where
C: Collect + ?Sized,
{
#[inline]
fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest {
self.as_ref().register_callsite(metadata)
Expand Down

0 comments on commit 68bc91f

Please sign in to comment.