Skip to content

Commit

Permalink
core: impl<S: Subscriber + ?Sized> Subscriber for Box<S>, Arc<S> (
Browse files Browse the repository at this point in the history
#2161)

These broader impls supersede the previous impls where the inner type was a
`dyn Subscriber`. With these generic impls, you no longer must (but
still can, if you wish) cast the inner type of a boxed or arc'd
subscriber to `dyn Subscriber` to use it as a `Subscriber`.
  • Loading branch information
jswrenn authored and hawkw committed Jun 22, 2022
1 parent f90b455 commit a6cb13e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tracing-core/src/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,10 @@ impl Subscriber for NoSubscriber {
fn exit(&self, _span: &span::Id) {}
}

impl Subscriber for Box<dyn Subscriber + Send + Sync + 'static> {
impl<S> Subscriber for Box<S>
where
S: Subscriber + ?Sized,
{
#[inline]
fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest {
self.as_ref().register_callsite(metadata)
Expand Down Expand Up @@ -739,7 +742,10 @@ impl Subscriber for Box<dyn Subscriber + Send + Sync + 'static> {
}
}

impl Subscriber for Arc<dyn Subscriber + Send + Sync + 'static> {
impl<S> Subscriber for Arc<S>
where
S: Subscriber + ?Sized,
{
#[inline]
fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest {
self.as_ref().register_callsite(metadata)
Expand Down

0 comments on commit a6cb13e

Please sign in to comment.