Skip to content

Commit

Permalink
fix max_level_hint on nostd
Browse files Browse the repository at this point in the history
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
  • Loading branch information
hawkw committed Apr 20, 2022
1 parent a9893a6 commit 4a30546
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
29 changes: 20 additions & 9 deletions tracing-core/src/callsite.rs
Expand Up @@ -420,31 +420,42 @@ mod dispatchers {
#[cfg(not(feature = "std"))]
mod dispatchers {
use crate::dispatcher;
use core::marker::PhantomData;

pub(super) struct Dispatchers(());
pub(super) struct Rebuilder<'a>(PhantomData<&'a ()>);
pub(super) struct Rebuilder<'a>(Option<&'a dispatcher::Dispatch>);

impl Dispatchers {
pub(super) const fn new() -> Self {
Self(())
}

pub(super) fn rebuilder(&self) -> Rebuilder<'_> {
Rebuilder(PhantomData)
}
Rebuilder(None)
}E

pub(super) fn register_dispatch(&self, _: &dispatcher::Dispatch) -> Rebuilder<'_> {
pub(super) fn register_dispatch<'dispatch>(
&self,
dispatch: &'dispatch dispatcher::Dispatch,
) -> Rebuilder<'dispatch> {
// nop; on no_std, there can only ever be one dispatcher
Rebuilder(PhantomData)
Rebuilder(Some(dispatch))
}
}

impl Rebuilder<'_> {
#[inline(always)]
#[inline]
pub(super) fn for_each(&self, mut f: impl FnMut(&dispatcher::Dispatch)) {
// on no_std, there can only ever be one dispatcher
dispatcher::get_default(f)
if let Some(dispatch) = self.0 {
// we are rebuilding the interest cache because a new dispatcher
// is about to be set. on `no_std`, this should only happen
// once, because the new dispatcher will be the global default.
f(dispatch)
} else {
// otherwise, we are rebuilding the cache because the subscriber
// configuration changed, so use the global default.
// on no_std, there can only ever be one dispatcher
dispatcher::get_default(f)
}
}
}
}
2 changes: 2 additions & 0 deletions tracing-mock/src/subscriber.rs
Expand Up @@ -198,7 +198,9 @@ where
Interest::never()
}
}

fn max_level_hint(&self) -> Option<LevelFilter> {
println!("[{}] max_level_hint -> {:?}", self.name, self.max_level);
self.max_level
}

Expand Down

0 comments on commit 4a30546

Please sign in to comment.