Skip to content

Commit

Permalink
Merge branch 'v0.1.x' into inst-skip_all
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw authored Sep 11, 2021
2 parents f28a62a + 4f5ef51 commit d848e84
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 32 deletions.
34 changes: 4 additions & 30 deletions tracing-core/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
//! [`Dispatch`]: struct.Dispatch.html
use crate::{
callsite, span,
subscriber::{self, Subscriber},
subscriber::{self, NoSubscriber, Subscriber},
Event, LevelFilter, Metadata,
};

Expand Down Expand Up @@ -404,7 +404,7 @@ impl Dispatch {
#[inline]
pub fn none() -> Self {
Dispatch {
subscriber: Arc::new(NoSubscriber),
subscriber: Arc::new(NoSubscriber::default()),
}
}

Expand Down Expand Up @@ -661,32 +661,6 @@ where
}
}

struct NoSubscriber;
impl Subscriber for NoSubscriber {
#[inline]
fn register_callsite(&self, _: &'static Metadata<'static>) -> subscriber::Interest {
subscriber::Interest::never()
}

fn new_span(&self, _: &span::Attributes<'_>) -> span::Id {
span::Id::from_u64(0xDEAD)
}

fn event(&self, _event: &Event<'_>) {}

fn record(&self, _span: &span::Id, _values: &span::Record<'_>) {}

fn record_follows_from(&self, _span: &span::Id, _follows: &span::Id) {}

#[inline]
fn enabled(&self, _metadata: &Metadata<'_>) -> bool {
false
}

fn enter(&self, _span: &span::Id) {}
fn exit(&self, _span: &span::Id) {}
}

impl Registrar {
pub(crate) fn try_register(
&self,
Expand Down Expand Up @@ -789,13 +763,13 @@ mod test {

#[test]
fn dispatch_is() {
let dispatcher = Dispatch::new(NoSubscriber);
let dispatcher = Dispatch::new(NoSubscriber::default());
assert!(dispatcher.is::<NoSubscriber>());
}

#[test]
fn dispatch_downcasts() {
let dispatcher = Dispatch::new(NoSubscriber);
let dispatcher = Dispatch::new(NoSubscriber::default());
assert!(dispatcher.downcast_ref::<NoSubscriber>().is_some());
}

Expand Down
38 changes: 38 additions & 0 deletions tracing-core/src/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,44 @@ impl Interest {
}
}

/// A no-op [`Subscriber`]
///
/// [`NoSubscriber`] implements the [`Subscriber`] trait by never being enabled,
/// never being interested in any callsite, and drops all spans and events.
#[derive(Debug, Copy, Clone)]
pub struct NoSubscriber(());

impl Default for NoSubscriber {
fn default() -> Self {
NoSubscriber(())
}
}

impl Subscriber for NoSubscriber {
#[inline]
fn register_callsite(&self, _: &'static Metadata<'static>) -> Interest {
Interest::never()
}

fn new_span(&self, _: &span::Attributes<'_>) -> span::Id {
span::Id::from_u64(0xDEAD)
}

fn event(&self, _event: &Event<'_>) {}

fn record(&self, _span: &span::Id, _values: &span::Record<'_>) {}

fn record_follows_from(&self, _span: &span::Id, _follows: &span::Id) {}

#[inline]
fn enabled(&self, _metadata: &Metadata<'_>) -> bool {
false
}

fn enter(&self, _span: &span::Id) {}
fn exit(&self, _span: &span::Id) {}
}

impl Subscriber for Box<dyn Subscriber + Send + Sync + 'static> {
#[inline]
fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest {
Expand Down
4 changes: 2 additions & 2 deletions tracing-subscriber/src/layer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ where
layer_impl_body! {}
}

impl<S> Layer<S> for Arc<dyn Layer<S>>
impl<S> Layer<S> for Arc<dyn Layer<S> + Send + Sync>
where
S: Subscriber,
{
Expand All @@ -1165,7 +1165,7 @@ where
layer_impl_body! {}
}

impl<S> Layer<S> for Box<dyn Layer<S>>
impl<S> Layer<S> for Box<dyn Layer<S> + Send + Sync>
where
S: Subscriber,
{
Expand Down

0 comments on commit d848e84

Please sign in to comment.