Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.1: add Layer implementations for various containers #1536

Merged
merged 2 commits into from
Sep 4, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
268 changes: 268 additions & 0 deletions tracing-subscriber/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use std::{
any::{type_name, TypeId},
fmt,
marker::PhantomData,
ops::Deref,
sync::Arc,
};

/// A composable handler for `tracing` events.
Expand Down Expand Up @@ -917,6 +919,272 @@ where
}
}

impl<L, S> Layer<S> for Arc<L>
where
L: Layer<S>,
S: Subscriber,
{
#[inline]
fn new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) {
self.deref().new_span(attrs, id, ctx)
}

#[inline]
fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest {
self.deref().register_callsite(metadata)
}

#[inline]
fn enabled(&self, metadata: &Metadata<'_>, ctx: Context<'_, S>) -> bool {
self.deref().enabled(metadata, ctx)
}

#[inline]
fn max_level_hint(&self) -> Option<LevelFilter> {
self.deref().max_level_hint()
}

#[inline]
fn on_record(&self, span: &span::Id, values: &span::Record<'_>, ctx: Context<'_, S>) {
self.deref().on_record(span, values, ctx)
}

#[inline]
fn on_follows_from(&self, span: &span::Id, follows: &span::Id, ctx: Context<'_, S>) {
self.deref().on_follows_from(span, follows, ctx)
}

#[inline]
fn on_event(&self, event: &Event<'_>, ctx: Context<'_, S>) {
self.deref().on_event(event, ctx)
}

#[inline]
fn on_enter(&self, id: &span::Id, ctx: Context<'_, S>) {
self.deref().on_enter(id, ctx)
}

#[inline]
fn on_exit(&self, id: &span::Id, ctx: Context<'_, S>) {
self.deref().on_exit(id, ctx)
}

#[inline]
fn on_close(&self, id: span::Id, ctx: Context<'_, S>) {
self.deref().on_close(id, ctx)
}

#[inline]
fn on_id_change(&self, old: &span::Id, new: &span::Id, ctx: Context<'_, S>) {
self.deref().on_id_change(old, new, ctx)
}

#[doc(hidden)]
#[inline]
unsafe fn downcast_raw(&self, id: TypeId) -> Option<*const ()> {
self.deref().downcast_raw(id)
}
}

impl<S> Layer<S> for Arc<dyn Layer<S>>
where
S: Subscriber,
{
#[inline]
fn new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) {
self.deref().new_span(attrs, id, ctx)
}

#[inline]
fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest {
self.deref().register_callsite(metadata)
}

#[inline]
fn enabled(&self, metadata: &Metadata<'_>, ctx: Context<'_, S>) -> bool {
self.deref().enabled(metadata, ctx)
}

#[inline]
fn max_level_hint(&self) -> Option<LevelFilter> {
self.deref().max_level_hint()
}

#[inline]
fn on_record(&self, span: &span::Id, values: &span::Record<'_>, ctx: Context<'_, S>) {
self.deref().on_record(span, values, ctx)
}

#[inline]
fn on_follows_from(&self, span: &span::Id, follows: &span::Id, ctx: Context<'_, S>) {
self.deref().on_follows_from(span, follows, ctx)
}

#[inline]
fn on_event(&self, event: &Event<'_>, ctx: Context<'_, S>) {
self.deref().on_event(event, ctx)
}

#[inline]
fn on_enter(&self, id: &span::Id, ctx: Context<'_, S>) {
self.deref().on_enter(id, ctx)
}

#[inline]
fn on_exit(&self, id: &span::Id, ctx: Context<'_, S>) {
self.deref().on_exit(id, ctx)
}

#[inline]
fn on_close(&self, id: span::Id, ctx: Context<'_, S>) {
self.deref().on_close(id, ctx)
}

#[inline]
fn on_id_change(&self, old: &span::Id, new: &span::Id, ctx: Context<'_, S>) {
self.deref().on_id_change(old, new, ctx)
}

#[doc(hidden)]
#[inline]
unsafe fn downcast_raw(&self, id: TypeId) -> Option<*const ()> {
self.deref().downcast_raw(id)
}
}

impl<L, S> Layer<S> for Box<L>
where
L: Layer<S>,
S: Subscriber,
{
#[inline]
fn new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) {
self.deref().new_span(attrs, id, ctx)
}

#[inline]
fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest {
self.deref().register_callsite(metadata)
}

#[inline]
fn enabled(&self, metadata: &Metadata<'_>, ctx: Context<'_, S>) -> bool {
self.deref().enabled(metadata, ctx)
}

#[inline]
fn max_level_hint(&self) -> Option<LevelFilter> {
self.deref().max_level_hint()
}

#[inline]
fn on_record(&self, span: &span::Id, values: &span::Record<'_>, ctx: Context<'_, S>) {
self.deref().on_record(span, values, ctx)
}

#[inline]
fn on_follows_from(&self, span: &span::Id, follows: &span::Id, ctx: Context<'_, S>) {
self.deref().on_follows_from(span, follows, ctx)
}

#[inline]
fn on_event(&self, event: &Event<'_>, ctx: Context<'_, S>) {
self.deref().on_event(event, ctx)
}

#[inline]
fn on_enter(&self, id: &span::Id, ctx: Context<'_, S>) {
self.deref().on_enter(id, ctx)
}

#[inline]
fn on_exit(&self, id: &span::Id, ctx: Context<'_, S>) {
self.deref().on_exit(id, ctx)
}

#[inline]
fn on_close(&self, id: span::Id, ctx: Context<'_, S>) {
self.deref().on_close(id, ctx)
}

#[inline]
fn on_id_change(&self, old: &span::Id, new: &span::Id, ctx: Context<'_, S>) {
self.deref().on_id_change(old, new, ctx)
}

#[doc(hidden)]
#[inline]
unsafe fn downcast_raw(&self, id: TypeId) -> Option<*const ()> {
self.deref().downcast_raw(id)
}
}

impl<S> Layer<S> for Box<dyn Layer<S>>
where
S: Subscriber,
{
#[inline]
fn new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) {
self.deref().new_span(attrs, id, ctx)
}

#[inline]
fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest {
self.deref().register_callsite(metadata)
}

#[inline]
fn enabled(&self, metadata: &Metadata<'_>, ctx: Context<'_, S>) -> bool {
self.deref().enabled(metadata, ctx)
}

#[inline]
fn max_level_hint(&self) -> Option<LevelFilter> {
self.deref().max_level_hint()
}

#[inline]
fn on_record(&self, span: &span::Id, values: &span::Record<'_>, ctx: Context<'_, S>) {
self.deref().on_record(span, values, ctx)
}

#[inline]
fn on_follows_from(&self, span: &span::Id, follows: &span::Id, ctx: Context<'_, S>) {
self.deref().on_follows_from(span, follows, ctx)
}

#[inline]
fn on_event(&self, event: &Event<'_>, ctx: Context<'_, S>) {
self.deref().on_event(event, ctx)
}

#[inline]
fn on_enter(&self, id: &span::Id, ctx: Context<'_, S>) {
self.deref().on_enter(id, ctx)
}

#[inline]
fn on_exit(&self, id: &span::Id, ctx: Context<'_, S>) {
self.deref().on_exit(id, ctx)
}

#[inline]
fn on_close(&self, id: span::Id, ctx: Context<'_, S>) {
self.deref().on_close(id, ctx)
}

#[inline]
fn on_id_change(&self, old: &span::Id, new: &span::Id, ctx: Context<'_, S>) {
self.deref().on_id_change(old, new, ctx)
}

#[doc(hidden)]
#[inline]
unsafe fn downcast_raw(&self, id: TypeId) -> Option<*const ()> {
self.deref().downcast_raw(id)
}
}

impl<'a, L, S> LookupSpan<'a> for Layered<L, S>
where
S: Subscriber + LookupSpan<'a>,
Expand Down