Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Commit

Permalink
reduce surface area a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus committed Feb 9, 2024
1 parent 8a2c124 commit 4c98450
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 196 deletions.
2 changes: 1 addition & 1 deletion core/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub trait Emitter {

fn blocking_flush(&self, timeout: Duration);

fn and_emitter<U>(self, other: U) -> And<Self, U>
fn and_to<U>(self, other: U) -> And<Self, U>
where
Self: Sized,
{
Expand Down
4 changes: 2 additions & 2 deletions core/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
pub trait Filter {
fn matches<P: Props>(&self, evt: &Event<P>) -> bool;

fn and_filter<U>(self, other: U) -> And<Self, U>
fn and_when<U>(self, other: U) -> And<Self, U>
where
Self: Sized,
{
Expand All @@ -20,7 +20,7 @@ pub trait Filter {
}
}

fn or<U>(self, other: U) -> Or<Self, U>
fn or_filter<U>(self, other: U) -> Or<Self, U>
where
Self: Sized,
{
Expand Down
12 changes: 6 additions & 6 deletions core/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,27 +192,27 @@ impl<TEmitter: Emitter, TFilter: Filter, TCtxt: Ctxt, TClock: Clock, TRng: Rng>
}
}

impl<TEmitter: Emitter, TFilter, TCtxt, TClock, TRng> Emitter
impl<TEmitter: Emitter, TFilter: Filter, TCtxt: Ctxt, TClock: Clock, TRng: Rng> Emitter
for Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>
{
fn emit<P: Props>(&self, evt: &Event<P>) {
self.emitter.emit(evt)
self.emit(evt)
}

fn blocking_flush(&self, timeout: core::time::Duration) {
self.emitter.blocking_flush(timeout)
}
}

impl<TEmitter, TFilter: Filter, TCtxt, TClock, TRng> Filter
impl<TEmitter: Emitter, TFilter: Filter, TCtxt: Ctxt, TClock: Clock, TRng: Rng> Filter
for Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>
{
fn matches<P: Props>(&self, evt: &Event<P>) -> bool {
self.filter.matches(evt)
}
}

impl<TEmitter, TFilter, TCtxt: Ctxt, TClock, TRng> Ctxt
impl<TEmitter: Emitter, TFilter: Filter, TCtxt: Ctxt, TClock: Clock, TRng: Rng> Ctxt
for Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>
{
type Current = TCtxt::Current;
Expand Down Expand Up @@ -243,15 +243,15 @@ impl<TEmitter, TFilter, TCtxt: Ctxt, TClock, TRng> Ctxt
}
}

impl<TEmitter, TFilter, TCtxt, TClock: Clock, TRng> Clock
impl<TEmitter: Emitter, TFilter: Filter, TCtxt: Ctxt, TClock: Clock, TRng: Rng> Clock
for Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>
{
fn now(&self) -> Option<Timestamp> {
self.clock.now()
}
}

impl<TEmitter, TFilter, TCtxt, TClock, TRng: Rng> Rng
impl<TEmitter: Emitter, TFilter: Filter, TCtxt: Ctxt, TClock: Clock, TRng: Rng> Rng
for Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>
{
fn gen_u64(&self) -> Option<u64> {
Expand Down
35 changes: 2 additions & 33 deletions src/id.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
use emit_core::{
ctxt::Ctxt,
props::Props,
rng::Rng,
value::FromValue,
well_known::{SPAN_ID_KEY, TRACE_ID_KEY},
};
use emit_core::{rng::Rng, value::FromValue};

use crate::value::{ToValue, Value};
use core::{
Expand Down Expand Up @@ -304,7 +298,7 @@ impl<const N: usize> fmt::Write for Buffer<N> {
}
}

pub trait IdRng: Rng {
pub trait IdRng {
fn gen_trace_id(&self) -> Option<TraceId>;

fn gen_span_id(&self) -> Option<SpanId>;
Expand All @@ -325,31 +319,6 @@ impl<T: Rng + ?Sized> IdRng for T {
}
}

pub trait IdCtxt: Ctxt {
fn current_trace_id(&self) -> Option<TraceId>;
fn current_span_id(&self) -> Option<SpanId>;
}

impl<C: Ctxt + ?Sized> IdCtxt for C {
fn current_span_id(&self) -> Option<SpanId> {
let mut span_id = None;
self.with_current(|current| {
span_id = current.pull(SPAN_ID_KEY);
});

span_id
}

fn current_trace_id(&self) -> Option<TraceId> {
let mut trace_id = None;
self.with_current(|current| {
trace_id = current.pull(TRACE_ID_KEY);
});

trace_id
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
98 changes: 3 additions & 95 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[cfg(feature = "alloc")]
extern crate alloc;

use emit_core::{extent::ToExtent, well_known::LVL_KEY};
use emit_core::extent::ToExtent;

#[doc(inline)]
pub use emit_macros::*;
Expand All @@ -27,13 +27,13 @@ pub use self::{
extent::Extent,
filter::Filter,
frame::FrameCtxt,
id::{IdCtxt, IdRng, SpanId, TraceId},
id::{IdRng, SpanId, TraceId},
level::Level,
props::Props,
rng::Rng,
str::Str,
template::Template,
timer::{StartTimer, Timer},
timer::Timer,
timestamp::Timestamp,
value::Value,
};
Expand Down Expand Up @@ -64,98 +64,6 @@ fn base_emit(
});
}

pub trait Emit: Emitter + Filter + Ctxt + Clock + Rng {
fn debug<P: Props>(&self, tpl: Template, props: P) {
base_emit(
self,
self,
self,
self.now(),
tpl,
props.chain((LVL_KEY, Level::Debug)),
)
}

fn info<P: Props>(&self, tpl: Template, props: P) {
base_emit(
self,
self,
self,
self.now(),
tpl,
props.chain((LVL_KEY, Level::Info)),
)
}

fn warn<P: Props>(&self, tpl: Template, props: P) {
base_emit(
self,
self,
self,
self.now(),
tpl,
props.chain((LVL_KEY, Level::Warn)),
)
}

fn error<P: Props>(&self, tpl: Template, props: P) {
base_emit(
self,
self,
self,
self.now(),
tpl,
props.chain((LVL_KEY, Level::Error)),
)
}

fn debug_at<E: ToExtent, P: Props>(&self, extent: E, tpl: Template, props: P) {
base_emit(
self,
self,
self,
extent,
tpl,
props.chain((LVL_KEY, Level::Debug)),
)
}

fn info_at<E: ToExtent, P: Props>(&self, extent: E, tpl: Template, props: P) {
base_emit(
self,
self,
self,
extent,
tpl,
props.chain((LVL_KEY, Level::Info)),
)
}

fn warn_at<E: ToExtent, P: Props>(&self, extent: E, tpl: Template, props: P) {
base_emit(
self,
self,
self,
extent,
tpl,
props.chain((LVL_KEY, Level::Warn)),
)
}

fn error_at<E: ToExtent, P: Props>(&self, extent: E, tpl: Template, props: P) {
base_emit(
self,
self,
self,
extent,
tpl,
props.chain((LVL_KEY, Level::Error)),
)
}
}

impl<E: Emitter + Filter + Ctxt + Clock + Rng + ?Sized> Emit for E {}

#[doc(hidden)]
pub mod __private {
pub use crate::macro_hooks::*;
Expand Down
4 changes: 2 additions & 2 deletions src/macro_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ pub fn __private_emit(
let rt = crate::runtime::shared();

base_emit(
rt.emitter().and_emitter(to),
rt.filter().and_filter(when),
rt.emitter().and_to(to),
rt.filter().and_when(when),
rt.ctxt(),
extent.to_extent().or_else(|| rt.now().to_extent()),
tpl,
Expand Down
2 changes: 1 addition & 1 deletion src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl<TEmitter: Emitter, TFilter: Filter, TCtxt: Ctxt> Setup<TEmitter, TFilter, T
emitter: UEmitter,
) -> Setup<emitter::And<TEmitter, UEmitter>, TFilter, TCtxt> {
Setup {
emitter: self.emitter.and_emitter(emitter),
emitter: self.emitter.and_to(emitter),
filter: self.filter,
ctxt: self.ctxt,
platform: self.platform,
Expand Down
10 changes: 0 additions & 10 deletions src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@ use core::time::Duration;

use crate::{Clock, Extent, Timestamp, ToExtent};

pub trait StartTimer: Clock {
fn start_timer(&self) -> Timer<&Self>;
}

impl<C: Clock + ?Sized> StartTimer for C {
fn start_timer(&self) -> Timer<&Self> {
Timer::start(self)
}
}

#[derive(Clone, Copy)]
pub struct Timer<C> {
start: Option<Timestamp>,
Expand Down
Loading

0 comments on commit 4c98450

Please sign in to comment.