diff --git a/Cargo.toml b/Cargo.toml index 36604fb..2517cfc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,6 @@ members = [ "targets/otlp/gen", "macros", "benchmark", - "tests/ui", ] exclude = [ "tests/smoke-test" diff --git a/core/src/ambient.rs b/core/src/ambient.rs index 852177a..47a6afc 100644 --- a/core/src/ambient.rs +++ b/core/src/ambient.rs @@ -129,26 +129,26 @@ impl Filter impl Ctxt for Ambient { - type CurrentProps = TCtxt::CurrentProps; - type LocalFrame = TCtxt::LocalFrame; + type Props = TCtxt::Props; + type Frame = TCtxt::Frame; - fn open(&self, props: P) -> Self::LocalFrame { + fn open(&self, props: P) -> Self::Frame { self.ctxt.open(props) } - fn enter(&self, scope: &mut Self::LocalFrame) { + fn enter(&self, scope: &mut Self::Frame) { self.ctxt.enter(scope) } - fn with_current(&self, with: F) { + fn with_current(&self, with: F) { self.ctxt.with_current(with) } - fn exit(&self, scope: &mut Self::LocalFrame) { + fn exit(&self, scope: &mut Self::Frame) { self.ctxt.exit(scope) } - fn close(&self, span: Self::LocalFrame) { + fn close(&self, span: Self::Frame) { self.ctxt.close(span) } } @@ -293,7 +293,7 @@ mod std_support { TEmitter: Emitter + Send + Sync + 'static, TFilter: Filter + Send + Sync + 'static, TCtxt: Ctxt + Send + Sync + 'static, - TCtxt::LocalFrame: Send + 'static, + TCtxt::Frame: Send + 'static, TClock: Clock + Send + Sync + 'static, TIdGen: IdGen + Send + Sync + 'static, { diff --git a/core/src/ctxt.rs b/core/src/ctxt.rs index ad24229..0de1548 100644 --- a/core/src/ctxt.rs +++ b/core/src/ctxt.rs @@ -1,18 +1,18 @@ use crate::{empty::Empty, props::Props}; pub trait Ctxt { - type CurrentProps: Props + ?Sized; - type LocalFrame; + type Props: Props + ?Sized; + type Frame; - fn open(&self, props: P) -> Self::LocalFrame; + fn open(&self, props: P) -> Self::Frame; - fn enter(&self, local: &mut Self::LocalFrame); + fn enter(&self, local: &mut Self::Frame); - fn with_current(&self, with: F); + fn with_current(&self, with: F); - fn exit(&self, local: &mut Self::LocalFrame); + fn exit(&self, local: &mut Self::Frame); - fn close(&self, frame: Self::LocalFrame); + fn close(&self, frame: Self::Frame); fn by_ref(&self) -> ByRef { ByRef(self) @@ -20,35 +20,35 @@ pub trait Ctxt { } impl<'a, C: Ctxt + ?Sized> Ctxt for &'a C { - type CurrentProps = C::CurrentProps; - type LocalFrame = C::LocalFrame; + type Props = C::Props; + type Frame = C::Frame; - fn open(&self, props: P) -> Self::LocalFrame { + fn open(&self, props: P) -> Self::Frame { (**self).open(props) } - fn enter(&self, frame: &mut Self::LocalFrame) { + fn enter(&self, frame: &mut Self::Frame) { (**self).enter(frame) } - fn with_current(&self, with: F) { + fn with_current(&self, with: F) { (**self).with_current(with) } - fn exit(&self, frame: &mut Self::LocalFrame) { + fn exit(&self, frame: &mut Self::Frame) { (**self).exit(frame) } - fn close(&self, frame: Self::LocalFrame) { + fn close(&self, frame: Self::Frame) { (**self).close(frame) } } impl Ctxt for Option { - type CurrentProps = Option>; - type LocalFrame = Option; + type Props = Option>; + type Frame = Option; - fn with_current(&self, with: F) { + fn with_current(&self, with: F) { match self { Some(ctxt) => { ctxt.with_current(|props| unsafe { with(&Some(internal::Slot::new(props))) }) @@ -57,23 +57,23 @@ impl Ctxt for Option { } } - fn open(&self, props: P) -> Self::LocalFrame { + fn open(&self, props: P) -> Self::Frame { self.as_ref().map(|ctxt| ctxt.open(props)) } - fn enter(&self, frame: &mut Self::LocalFrame) { + fn enter(&self, frame: &mut Self::Frame) { if let (Some(ctxt), Some(span)) = (self, frame) { ctxt.enter(span) } } - fn exit(&self, frame: &mut Self::LocalFrame) { + fn exit(&self, frame: &mut Self::Frame) { if let (Some(ctxt), Some(span)) = (self, frame) { ctxt.exit(span) } } - fn close(&self, frame: Self::LocalFrame) { + fn close(&self, frame: Self::Frame) { if let (Some(ctxt), Some(span)) = (self, frame) { ctxt.close(span) } @@ -82,26 +82,26 @@ impl Ctxt for Option { #[cfg(feature = "alloc")] impl<'a, C: Ctxt + ?Sized + 'a> Ctxt for alloc::boxed::Box { - type CurrentProps = C::CurrentProps; - type LocalFrame = C::LocalFrame; + type Props = C::Props; + type Frame = C::Frame; - fn with_current(&self, with: F) { + fn with_current(&self, with: F) { (**self).with_current(with) } - fn open(&self, props: P) -> Self::LocalFrame { + fn open(&self, props: P) -> Self::Frame { (**self).open(props) } - fn enter(&self, frame: &mut Self::LocalFrame) { + fn enter(&self, frame: &mut Self::Frame) { (**self).enter(frame) } - fn exit(&self, frame: &mut Self::LocalFrame) { + fn exit(&self, frame: &mut Self::Frame) { (**self).exit(frame) } - fn close(&self, frame: Self::LocalFrame) { + fn close(&self, frame: Self::Frame) { (**self).close(frame) } } @@ -109,48 +109,48 @@ impl<'a, C: Ctxt + ?Sized + 'a> Ctxt for alloc::boxed::Box { pub struct ByRef<'a, T: ?Sized>(&'a T); impl<'a, T: Ctxt + ?Sized> Ctxt for ByRef<'a, T> { - type CurrentProps = T::CurrentProps; + type Props = T::Props; - type LocalFrame = T::LocalFrame; + type Frame = T::Frame; - fn open(&self, props: P) -> Self::LocalFrame { + fn open(&self, props: P) -> Self::Frame { self.0.open(props) } - fn enter(&self, frame: &mut Self::LocalFrame) { + fn enter(&self, frame: &mut Self::Frame) { self.0.enter(frame) } - fn with_current(&self, with: F) { + fn with_current(&self, with: F) { self.0.with_current(with) } - fn exit(&self, frame: &mut Self::LocalFrame) { + fn exit(&self, frame: &mut Self::Frame) { self.0.exit(frame) } - fn close(&self, frame: Self::LocalFrame) { + fn close(&self, frame: Self::Frame) { self.0.close(frame) } } impl Ctxt for Empty { - type CurrentProps = Empty; - type LocalFrame = Empty; + type Props = Empty; + type Frame = Empty; - fn with_current(&self, with: F) { + fn with_current(&self, with: F) { with(&Empty) } - fn open(&self, _: P) -> Self::LocalFrame { + fn open(&self, _: P) -> Self::Frame { Empty } - fn enter(&self, _: &mut Self::LocalFrame) {} + fn enter(&self, _: &mut Self::Frame) {} - fn exit(&self, _: &mut Self::LocalFrame) {} + fn exit(&self, _: &mut Self::Frame) {} - fn close(&self, _: Self::LocalFrame) {} + fn close(&self, _: Self::Frame) {} } mod internal { @@ -246,11 +246,11 @@ mod alloc_support { pub trait ErasedCtxt: internal::SealedCtxt {} - impl ErasedCtxt for C where C::LocalFrame: Send + 'static {} + impl ErasedCtxt for C where C::Frame: Send + 'static {} impl internal::SealedCtxt for C where - C::LocalFrame: Send + 'static, + C::Frame: Send + 'static, { fn erase_ctxt(&self) -> crate::internal::Erased<&dyn internal::DispatchCtxt> { crate::internal::Erased(self) @@ -259,7 +259,7 @@ mod alloc_support { impl internal::DispatchCtxt for C where - C::LocalFrame: Send + 'static, + C::Frame: Send + 'static, { fn dispatch_with_current(&self, with: &mut dyn FnMut(internal::ErasedCurrentProps)) { self.with_current(move |props| { @@ -291,10 +291,10 @@ mod alloc_support { } impl<'a> Ctxt for dyn ErasedCtxt + 'a { - type CurrentProps = internal::ErasedCurrentProps; - type LocalFrame = ErasedLocalFrame; + type Props = internal::ErasedCurrentProps; + type Frame = ErasedLocalFrame; - fn with_current(&self, with: F) { + fn with_current(&self, with: F) { let mut f = Some(with); self.erase_ctxt().0.dispatch_with_current(&mut |props| { @@ -302,44 +302,44 @@ mod alloc_support { }); } - fn open(&self, props: P) -> Self::LocalFrame { + fn open(&self, props: P) -> Self::Frame { self.erase_ctxt().0.dispatch_open(&props) } - fn enter(&self, span: &mut Self::LocalFrame) { + fn enter(&self, span: &mut Self::Frame) { self.erase_ctxt().0.dispatch_enter(span) } - fn exit(&self, span: &mut Self::LocalFrame) { + fn exit(&self, span: &mut Self::Frame) { self.erase_ctxt().0.dispatch_exit(span) } - fn close(&self, span: Self::LocalFrame) { + fn close(&self, span: Self::Frame) { self.erase_ctxt().0.dispatch_close(span) } } impl<'a> Ctxt for dyn ErasedCtxt + Send + Sync + 'a { - type CurrentProps = ::CurrentProps; - type LocalFrame = ::LocalFrame; + type Props = ::Props; + type Frame = ::Frame; - fn with_current(&self, with: F) { + fn with_current(&self, with: F) { (self as &(dyn ErasedCtxt + 'a)).with_current(with) } - fn open(&self, props: P) -> Self::LocalFrame { + fn open(&self, props: P) -> Self::Frame { (self as &(dyn ErasedCtxt + 'a)).open(props) } - fn enter(&self, span: &mut Self::LocalFrame) { + fn enter(&self, span: &mut Self::Frame) { (self as &(dyn ErasedCtxt + 'a)).enter(span) } - fn exit(&self, span: &mut Self::LocalFrame) { + fn exit(&self, span: &mut Self::Frame) { (self as &(dyn ErasedCtxt + 'a)).exit(span) } - fn close(&self, span: Self::LocalFrame) { + fn close(&self, span: Self::Frame) { (self as &(dyn ErasedCtxt + 'a)).close(span) } } diff --git a/core/src/lib.rs b/core/src/lib.rs index 9586900..3c855fb 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -16,7 +16,6 @@ pub mod filter; pub mod id; pub mod key; pub mod level; -pub mod metrics; pub mod props; pub mod template; pub mod timestamp; diff --git a/core/src/metrics.rs b/core/src/metrics.rs deleted file mode 100644 index 2bbc5a8..0000000 --- a/core/src/metrics.rs +++ /dev/null @@ -1,95 +0,0 @@ -use core::ops::ControlFlow; - -use crate::{ - key::{Key, ToKey}, - props::Props, - value::{ToValue, Value}, - well_known::{ - METRIC_KIND_KEY, METRIC_KIND_MAX, METRIC_KIND_MIN, METRIC_KIND_SUM, METRIC_NAME_KEY, - METRIC_VALUE_KEY, - }, -}; - -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Metric<'m, T> { - name: Key<'m>, - kind: Key<'m>, - value: T, -} - -impl<'m, T> Metric<'m, T> { - pub const fn new(kind: Key<'m>, name: Key<'m>, value: T) -> Self { - Metric { name, kind, value } - } - - pub const fn sum(name: Key<'m>, value: T) -> Self { - Metric::new(Key::new(METRIC_KIND_SUM), name, value) - } - - pub fn is_sum(&self) -> bool { - self.kind() == METRIC_KIND_SUM - } - - pub const fn min(name: Key<'m>, value: T) -> Self { - Metric::new(Key::new(METRIC_KIND_MIN), name, value) - } - - pub fn is_min(&self) -> bool { - self.kind() == METRIC_KIND_MIN - } - - pub const fn max(name: Key<'m>, value: T) -> Self { - Metric::new(Key::new(METRIC_KIND_MAX), name, value) - } - - pub fn is_max(&self) -> bool { - self.kind() == METRIC_KIND_MAX - } - - pub const fn name(&self) -> &Key<'m> { - &self.name - } - - pub const fn kind(&self) -> &Key<'m> { - &self.kind - } - - pub const fn value(&self) -> &T { - &self.value - } - - pub fn value_mut(&mut self) -> &mut T { - &mut self.value - } -} - -impl<'m, V: ToValue> Props for Metric<'m, V> { - fn for_each<'kv, F: FnMut(Key<'kv>, Value<'kv>) -> ControlFlow<()>>( - &'kv self, - mut for_each: F, - ) -> ControlFlow<()> { - for_each(METRIC_NAME_KEY.to_key(), self.name.to_value())?; - for_each(METRIC_VALUE_KEY.to_key(), self.value.to_value())?; - for_each(METRIC_KIND_KEY.to_key(), self.kind.to_value())?; - - ControlFlow::Continue(()) - } -} - -#[cfg(test)] -mod tests { - use crate::well_known::WellKnown; - - use super::*; - - #[test] - fn metric_well_known() { - let metric = Metric::sum(Key::new("metric"), Value::from(1usize)); - - let well_known = WellKnown::metric(&metric).unwrap(); - - assert_eq!("metric", well_known.name()); - assert_eq!("sum", well_known.kind()); - assert_eq!(1.0, well_known.value().to_f64().unwrap()); - } -} diff --git a/core/src/well_known.rs b/core/src/well_known.rs index 18932af..e63e5cf 100644 --- a/core/src/well_known.rs +++ b/core/src/well_known.rs @@ -2,7 +2,6 @@ use crate::{ id::{SpanId, TraceId}, key::Key, level::Level, - metrics::Metric, props::Props, value::Value, }; @@ -46,14 +45,6 @@ pub trait WellKnown: Props { self.get(ERR_KEY) } - fn metric(&self) -> Option> { - Some(Metric::new( - self.metric_kind()?, - self.metric_name()?, - self.metric_value()?, - )) - } - fn metric_name(&self) -> Option { self.get(METRIC_NAME_KEY)?.to_key() } diff --git a/macros/src/capture.rs b/macros/src/capture.rs index 1dfa8d5..f499294 100644 --- a/macros/src/capture.rs +++ b/macros/src/capture.rs @@ -110,69 +110,3 @@ pub fn rename_hook_tokens( }, }) } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn key_value_with_hook_tokens() { - let cases = vec![ - ( - quote!( - #[a] - #[b] - a - ), - quote!( - #[a] - #[b] - { - use emit::__private::{__PrivateCaptureHook, __PrivateKeyHook}; - ( - emit::Key::new("a").__private_key_default(), - (a).__private_capture_as_default(), - ) - } - ), - ), - ( - quote!(#[a] #[b] a: 42), - quote!( - #[a] - #[b] - { - use emit::__private::{__PrivateCaptureHook, __PrivateKeyHook}; - ( - emit::Key::new("a").__private_key_default(), - (42).__private_capture_as_default(), - ) - } - ), - ), - ( - quote!(#[a] #[b] err: 42), - quote!( - #[a] - #[b] - { - use emit::__private::{__PrivateCaptureHook, __PrivateKeyHook}; - ( - emit::Key::new("err").__private_key_default(), - (42).__private_capture_as_error(), - ) - } - ), - ), - ]; - - for (expr, expected) in cases { - let fv = syn::parse2::(expr).unwrap(); - let attrs = &fv.attrs; - - let actual = key_value_with_hook(attrs, &fv); - - assert_eq!(expected.to_string(), actual.to_string()); - } - } -} diff --git a/macros/src/emit.rs b/macros/src/emit.rs index 21a49cb..07ba753 100644 --- a/macros/src/emit.rs +++ b/macros/src/emit.rs @@ -96,106 +96,3 @@ pub fn expand_tokens(opts: ExpandTokens) -> Result { } })) } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - #[rustfmt::skip] - fn expand_emit() { - let cases = vec![ - ( - quote!("Text and {b: 17} and {a} and {#[as_debug] c} and {d: String::from(\"short lived\")} and {#[cfg(disabled)] e}"), - quote!({ - match ( - { - use emit::__private::__PrivateCaptureHook; - (emit::Key::new("b"), (17).__private_capture_as_default()) - }, - { - use emit::__private::__PrivateCaptureHook; - (emit::Key::new("a"), (a).__private_capture_as_default()) - }, - #[as_debug] - { - use emit::__private::__PrivateCaptureHook; - (emit::Key::new("c"), (c).__private_capture_as_default()) - }, - { - use emit::__private::__PrivateCaptureHook; - (emit::Key::new("d"), (String::from ("short lived")).__private_capture_as_default()) - }, - #[cfg (disabled)] - { - { - use emit::__private::__PrivateCaptureHook; - (emit::Key::new("e"), (e).__private_capture_as_default()) - } - }, - #[cfg(not(disabled))] () - ) { - (__tmp0, __tmp1, __tmp2, __tmp3, __tmp4) => { - emit::emit( - emit::target::Empty, - emit::filter::Empty, - emit::props::Empty, - emit::Level::Info, - None, - emit::Template::new_ref(&[ - emit::template::Part::text ("Text and "), - { - use emit::__private::__PrivateFmtHook; - emit::template::Part::hole ("b").__private_fmt_as_default() - }, - emit::template::Part::text (" and "), - { - use emit::__private::__PrivateFmtHook; - emit::template::Part::hole ("a").__private_fmt_as_default() - }, - emit::template::Part::text (" and "), - #[as_debug] - { - use emit::__private::__PrivateFmtHook; - emit::template::Part::hole ("c").__private_fmt_as_default() - }, - emit::template::Part::text (" and "), - { - use emit::__private::__PrivateFmtHook; - emit::template::Part::hole ("d").__private_fmt_as_default() - }, - emit::template::Part::text (" and "), - #[cfg (disabled)] - { - { - use emit::__private::__PrivateFmtHook; - emit::template::Part::hole ("e").__private_fmt_as_default() - } - } - ]), - emit::props::SortedSlice::new_ref(&[ - (__tmp1.0.by_ref(), __tmp1.1.by_ref()), - (__tmp0.0.by_ref(), __tmp0.1.by_ref()), - (__tmp2.0.by_ref(), __tmp2.1.by_ref()), - (__tmp3.0.by_ref(), __tmp3.1.by_ref()), - #[cfg(disabled)] - (__tmp4.0.by_ref(), __tmp4.1.by_ref()) - ]), - ) - } - } - }), - ), - ]; - - for (expr, expected) in cases { - let actual = expand_tokens(ExpandTokens { - receiver: quote!(emit), - level: quote!(Info), - input: expr, - }).unwrap(); - - assert_eq!(expected.to_string(), actual.to_string()); - } - } -} diff --git a/macros/src/fmt.rs b/macros/src/fmt.rs index a3ca663..abcc8ba 100644 --- a/macros/src/fmt.rs +++ b/macros/src/fmt.rs @@ -105,54 +105,3 @@ pub fn rename_hook_tokens(opts: RenameHookTokens) -> Result proc_macro::TokenStream { - with::expand_tokens(with::ExpandTokens { - sync_receiver: quote!(__private::__private_with), - async_receiver: quote!(__private::__private_with), + in_ctxt::expand_tokens(in_ctxt::ExpandTokens { + sync_receiver: quote!(__private::__private_push_ctxt), + async_receiver: quote!(__private::__private_push_ctxt), input: TokenStream::from(args), item: TokenStream::from(item), }) diff --git a/metrics/src/lib.rs b/metrics/src/lib.rs index 9680176..a113743 100644 --- a/metrics/src/lib.rs +++ b/metrics/src/lib.rs @@ -1,6 +1,99 @@ -use std::{borrow::Cow, cmp, collections::HashMap, mem, ops::Range, time::Duration}; +use std::{ + borrow::Cow, + cmp, + collections::HashMap, + mem, + ops::{ControlFlow, Range}, + time::Duration, +}; + +use emit_core::{ + event::Event, + key::{Key, ToKey}, + props::Props, + timestamp::Timestamp, + value::{ToValue, Value}, + well_known::{ + WellKnown, METRIC_KIND_KEY, METRIC_KIND_MAX, METRIC_KIND_MIN, METRIC_KIND_SUM, + METRIC_NAME_KEY, METRIC_VALUE_KEY, + }, +}; + +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Metric<'m, T> { + name: Key<'m>, + kind: Key<'m>, + value: T, +} + +impl<'m> Metric<'m, Value<'m>> { + pub fn from_props(props: &'m (impl Props + ?Sized)) -> Option { + Some(Metric::new( + props.metric_kind()?, + props.metric_name()?, + props.metric_value()?, + )) + } +} + +impl<'m, T> Metric<'m, T> { + pub const fn new(kind: Key<'m>, name: Key<'m>, value: T) -> Self { + Metric { name, kind, value } + } + + pub const fn sum(name: Key<'m>, value: T) -> Self { + Metric::new(Key::new(METRIC_KIND_SUM), name, value) + } + + pub fn is_sum(&self) -> bool { + self.kind() == METRIC_KIND_SUM + } + + pub const fn min(name: Key<'m>, value: T) -> Self { + Metric::new(Key::new(METRIC_KIND_MIN), name, value) + } + + pub fn is_min(&self) -> bool { + self.kind() == METRIC_KIND_MIN + } + + pub const fn max(name: Key<'m>, value: T) -> Self { + Metric::new(Key::new(METRIC_KIND_MAX), name, value) + } + + pub fn is_max(&self) -> bool { + self.kind() == METRIC_KIND_MAX + } + + pub const fn name(&self) -> &Key<'m> { + &self.name + } + + pub const fn kind(&self) -> &Key<'m> { + &self.kind + } -use emit_core::{event::Event, props::Props, timestamp::Timestamp, well_known::WellKnown}; + pub const fn value(&self) -> &T { + &self.value + } + + pub fn value_mut(&mut self) -> &mut T { + &mut self.value + } +} + +impl<'m, V: ToValue> Props for Metric<'m, V> { + fn for_each<'kv, F: FnMut(Key<'kv>, Value<'kv>) -> ControlFlow<()>>( + &'kv self, + mut for_each: F, + ) -> ControlFlow<()> { + for_each(METRIC_NAME_KEY.to_key(), self.name.to_value())?; + for_each(METRIC_VALUE_KEY.to_key(), self.value.to_value())?; + for_each(METRIC_KIND_KEY.to_key(), self.kind.to_value())?; + + ControlFlow::Continue(()) + } +} pub struct MetricsCollector { bucketing: Bucketing, @@ -64,7 +157,7 @@ impl MetricsCollector { pub fn record_metric(&mut self, evt: &Event) -> bool { if let (Some(extent), Some(metric)) = ( evt.extent().and_then(|extent| extent.as_point()), - evt.props().metric(), + Metric::from_props(evt.props()), ) { if metric.is_sum() { if let Some(value) = metric.value().to_f64() { diff --git a/src/local_frame.rs b/src/frame.rs similarity index 70% rename from src/local_frame.rs rename to src/frame.rs index 74672e0..04d8079 100644 --- a/src/local_frame.rs +++ b/src/frame.rs @@ -7,17 +7,17 @@ use core::{ }; use emit_core::{ctxt::Ctxt, props::Props}; -pub struct LocalFrame { - scope: mem::ManuallyDrop, +pub struct Frame { + scope: mem::ManuallyDrop, ctxt: C, } -impl LocalFrame { +impl Frame { #[track_caller] pub fn new(ctxt: C, props: impl Props) -> Self { let scope = mem::ManuallyDrop::new(ctxt.open(props)); - LocalFrame { ctxt, scope } + Frame { ctxt, scope } } #[track_caller] @@ -31,8 +31,14 @@ impl LocalFrame { } #[track_caller] - pub fn into_future(self, future: F) -> LocalFrameFuture { - LocalFrameFuture { + pub fn with(mut self, scope: impl FnOnce() -> R) -> R { + let __guard = self.enter(); + scope() + } + + #[track_caller] + pub fn with_future(self, future: F) -> FrameFuture { + FrameFuture { frame: self, future, } @@ -40,7 +46,7 @@ impl LocalFrame { } pub struct EnterGuard<'a, C: Ctxt> { - scope: &'a mut LocalFrame, + scope: &'a mut Frame, _marker: PhantomData<*mut fn()>, } @@ -50,19 +56,19 @@ impl<'a, C: Ctxt> Drop for EnterGuard<'a, C> { } } -impl Drop for LocalFrame { +impl Drop for Frame { fn drop(&mut self) { self.ctxt .close(unsafe { mem::ManuallyDrop::take(&mut self.scope) }) } } -pub struct LocalFrameFuture { - frame: LocalFrame, +pub struct FrameFuture { + frame: Frame, future: F, } -impl Future for LocalFrameFuture { +impl Future for FrameFuture { type Output = F::Output; #[track_caller] diff --git a/src/lib.rs b/src/lib.rs index fbc1a3a..3ab535b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,18 +5,18 @@ extern crate alloc; use emit_core::extent::ToExtent; -use crate::local_frame::LocalFrame; +use crate::frame::Frame; #[doc(inline)] pub use emit_macros::*; #[doc(inline)] pub use emit_core::{ - clock, ctxt, emitter, empty, event, extent, filter, id, key, level, metrics, props, template, - timestamp, value, well_known, + clock, ctxt, emitter, empty, event, extent, filter, id, key, level, props, template, timestamp, + value, well_known, }; -pub mod local_frame; +pub mod frame; pub use self::{ clock::{Clock, Timer}, @@ -28,7 +28,6 @@ pub use self::{ id::{IdGen, SpanId, TraceId}, key::Key, level::Level, - metrics::Metric, props::Props, template::Template, timestamp::Timestamp, @@ -63,8 +62,8 @@ fn base_emit( } #[track_caller] -fn base_with(ctxt: C, props: impl Props) -> LocalFrame { - LocalFrame::new(ctxt, props) +fn base_push_ctxt(ctxt: C, props: impl Props) -> Frame { + Frame::new(ctxt, props) } #[track_caller] @@ -78,7 +77,7 @@ pub fn emit(evt: &Event) { base_emit(ambient, ambient, ambient, extent, tpl, props); } -pub type With = LocalFrame; +pub type PushCtxt = Frame; pub type StartTimer = Timer; @@ -88,8 +87,13 @@ pub fn now() -> Option { } #[track_caller] -pub fn with(props: impl Props) -> With { - base_with(emit_core::ambient::get(), props) +pub fn push_ctxt(props: impl Props) -> PushCtxt { + base_push_ctxt(emit_core::ambient::get(), props) +} + +#[track_caller] +pub fn current_ctxt() -> PushCtxt { + base_push_ctxt(emit_core::ambient::get(), empty::Empty) } #[track_caller] diff --git a/src/macro_hooks.rs b/src/macro_hooks.rs index c31447f..1e750f4 100644 --- a/src/macro_hooks.rs +++ b/src/macro_hooks.rs @@ -18,8 +18,8 @@ use emit_core::extent::ToExtent; use std::error::Error; use crate::{ - base_emit, base_with, - local_frame::LocalFrame, + base_emit, base_push_ctxt, + frame::Frame, template::{Formatter, Part}, Key, }; @@ -452,10 +452,10 @@ pub fn __private_emit( } #[track_caller] -pub fn __private_with(props: impl Props) -> LocalFrame { +pub fn __private_push_ctxt(props: impl Props) -> Frame { let ambient = ambient::get(); - base_with(ambient, props) + base_push_ctxt(ambient, props) } pub use core::module_path as loc; @@ -502,128 +502,3 @@ impl<'a> Props for __PrivateMacroProps<'a> { .and_then(|i| self.0[i].1.as_ref().map(|v| v.by_ref())) } } - -#[cfg(test)] -mod tests { - use super::*; - use std::{fmt, string::String}; - - #[test] - fn capture_default() { - struct SomeType; - - impl fmt::Display for SomeType { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "some type") - } - } - - // Capture an arbitrary `Display` - let _ = SomeType.__private_capture_as_default(); - - // Capture a structured number - assert_eq!(Some(42u64), 42u64.__private_capture_as_default().to_u64()); - - // Capture a borrowed (non-static) string - let v: &str = &String::from("a string"); - assert_eq!( - Some("a string"), - v.__private_capture_as_default().to_borrowed_str() - ); - - // Capture a value with parens - let _ = (SomeType).__private_capture_as_default(); - - // Capture and borrow a string as an expression - let v = SomeType; - match ( - v.__private_capture_as_default(), - String::from("a string").__private_capture_as_default(), - ) { - (a, b) => { - let _ = a; - let _ = b; - } - } - let _ = v; - } - - #[test] - fn capture_display() { - struct SomeType; - - impl fmt::Display for SomeType { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "some type") - } - } - - // Capture an arbitrary `Display` - let _ = SomeType.__private_capture_as_display(); - let _ = (&&&SomeType).__private_capture_anon_as_display(); - - // Capture a `&dyn Display` - let v: &dyn fmt::Display = &SomeType; - let _ = v.__private_capture_as_display(); - let _ = (&&&v).__private_capture_anon_as_display(); - } - - #[test] - fn capture_debug() { - struct SomeType; - - impl fmt::Debug for SomeType { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "some type") - } - } - - // Capture an arbitrary `Debug` - let _ = SomeType.__private_capture_as_debug(); - let _ = (&&&SomeType).__private_capture_anon_as_debug(); - - // Capture a `&dyn Debug` - let v: &dyn fmt::Debug = &SomeType; - let _ = v.__private_capture_as_debug(); - let _ = (&&&v).__private_capture_anon_as_debug(); - } - - #[test] - #[cfg(feature = "sval")] - fn capture_sval() { - let tuple = (1, 2, 3, 4, 5); - - // Capture an arbitrary `Value` - let _ = tuple.__private_capture_as_sval(); - let _ = (&&&tuple).__private_capture_anon_as_sval(); - } - - #[test] - #[cfg(feature = "serde")] - fn capture_serde() { - let tuple = (1, 2, 3, 4, 5); - - let _ = tuple.__private_capture_as_serde(); - let _ = (&&&tuple).__private_capture_anon_as_serde(); - } - - #[test] - #[cfg(feature = "std")] - fn capture_error() { - use std::io; - - // Capture an arbitrary `Error` - let err = io::Error::from(io::ErrorKind::Other); - assert!(err - .__private_capture_as_error() - .to_borrowed_error() - .is_some()); - - // Capture a `&dyn Error` - let err: &dyn Error = &err; - assert!(err - .__private_capture_as_error() - .to_borrowed_error() - .is_some()); - } -} diff --git a/src/platform/thread_local_ctxt.rs b/src/platform/thread_local_ctxt.rs index d3bb82e..a745d83 100644 --- a/src/platform/thread_local_ctxt.rs +++ b/src/platform/thread_local_ctxt.rs @@ -40,14 +40,14 @@ impl Props for ThreadLocalSpan { } impl Ctxt for ThreadLocalCtxt { - type CurrentProps = ThreadLocalSpan; - type LocalFrame = ThreadLocalSpan; + type Props = ThreadLocalSpan; + type Frame = ThreadLocalSpan; - fn with_current(&self, with: F) { + fn with_current(&self, with: F) { ACTIVE.with(|span| with(&*span.borrow())) } - fn open(&self, props: P) -> Self::LocalFrame { + fn open(&self, props: P) -> Self::Frame { let mut span = ACTIVE.with(|span| span.borrow().clone()); props.for_each(|k, v| { @@ -58,13 +58,13 @@ impl Ctxt for ThreadLocalCtxt { span } - fn enter(&self, link: &mut Self::LocalFrame) { + fn enter(&self, link: &mut Self::Frame) { ACTIVE.with(|span| std::mem::swap(link, &mut *span.borrow_mut())); } - fn exit(&self, link: &mut Self::LocalFrame) { + fn exit(&self, link: &mut Self::Frame) { ACTIVE.with(|span| std::mem::swap(link, &mut *span.borrow_mut())); } - fn close(&self, _: Self::LocalFrame) {} + fn close(&self, _: Self::Frame) {} } diff --git a/src/setup.rs b/src/setup.rs index 28ec4e0..a88c691 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -81,7 +81,7 @@ impl< TCtxt: Ctxt + Send + Sync + 'static, > Setup where - TCtxt::LocalFrame: Send + 'static, + TCtxt::Frame: Send + 'static, { #[must_use = "call `blocking_flush(std::time::Duration::from_secs(5))` at the end of `main` to ensure events are flushed."] pub fn init(self) -> Init<&'static TEmitter, &'static TCtxt> { diff --git a/tests/smoke-test/main.rs b/tests/smoke-test/main.rs index 69a4f3e..41214da 100644 --- a/tests/smoke-test/main.rs +++ b/tests/smoke-test/main.rs @@ -37,14 +37,12 @@ async fn main() { emitter.blocking_flush(Duration::from_secs(5)); } -#[emit::with(trace_id: emit::new_trace_id())] +#[emit::in_ctxt(trace_id: emit::new_trace_id())] async fn in_trace() -> Result<(), io::Error> { let mut futures = Vec::new(); for i in 0..100 { - futures.push(tokio::spawn( - emit::with(emit::empty::Empty).into_future(in_ctxt(i)), - )); + futures.push(tokio::spawn(emit::current_ctxt().with_future(in_ctxt(i)))); } for future in futures { @@ -56,7 +54,7 @@ async fn in_trace() -> Result<(), io::Error> { Ok(()) } -#[emit::with(span_id: emit::new_span_id(), span_parent: emit::current_span_id(), a)] +#[emit::in_ctxt(span_id: emit::new_span_id(), span_parent: emit::current_span_id(), a)] async fn in_ctxt(a: i32) -> Result<(), io::Error> { increment(&COUNT); @@ -90,7 +88,7 @@ async fn in_ctxt(a: i32) -> Result<(), io::Error> { r } -#[emit::with(b, bx: 90)] +#[emit::in_ctxt(b, bx: 90)] async fn in_ctxt2(b: i32) { emit::warn!( "something went wrong at {#[emit::as_debug] id: 42} with {x} and {y: true}!", @@ -110,7 +108,7 @@ fn increment(metric: &AtomicUsize) { fn sample_metrics() { let now = emit::now(); - for (metric, kind, name) in [( + for (metric_value, metric_kind, metric_name) in [( &COUNT, emit::well_known::METRIC_KIND_SUM, "smoke_test::count", @@ -118,11 +116,11 @@ fn sample_metrics() { emit::emit(&emit::Event::new( now, emit::tpl!("{metric_kind} of {metric_name} is {metric_value}"), - emit::metrics::Metric::new( - emit::key::Key::new(kind), - emit::key::Key::new(name), - metric.load(Ordering::Relaxed), - ), + emit::props! { + metric_kind, + metric_name, + metric_value: metric_value.load(Ordering::Relaxed), + }, )); } } diff --git a/tests/ui/Cargo.toml b/tests/ui/Cargo.toml deleted file mode 100644 index 8d28ec7..0000000 --- a/tests/ui/Cargo.toml +++ /dev/null @@ -1,33 +0,0 @@ -[package] -name = "emit-ui" -version = "0.0.0" -publish = false -edition = "2021" - -[lib] -path = "lib.rs" - -[dependencies.emit] -path = "../../" -features = [ - "std", - "sval", - "serde", -] - -[dependencies.serde] -version = "1" - -[dependencies.serde_derive] -version = "1" - -[dependencies.sval_json] -version = "1.0.0-alpha.5" -features = ["std"] - -[dependencies.uuid] -version = "0.8" -features = ["v4", "serde"] - -[dependencies.trybuild] -version = "1" diff --git a/tests/ui/fail/log_cfg_unused.rs b/tests/ui/fail/log_cfg_unused.rs deleted file mode 100644 index 6940446..0000000 --- a/tests/ui/fail/log_cfg_unused.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![feature(stmt_expr_attributes, proc_macro_hygiene)] -#![deny(unused_variables)] - -fn main() { - let a = String::from("hello"); - - // Unused by the log statement - let c = 42; - - emit::info!("A log with cfgs {#[cfg(disabled)] b: 17}", - a, - #[emit::as_debug] - #[cfg(disabled)] - c, - d: String::from("short lived!"), - ); -} diff --git a/tests/ui/fail/log_cfg_unused.stderr b/tests/ui/fail/log_cfg_unused.stderr deleted file mode 100644 index 5837668..0000000 --- a/tests/ui/fail/log_cfg_unused.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: unused variable: `c` - --> $DIR/log_cfg_unused.rs:8:9 - | -8 | let c = 42; - | ^ help: if this is intentional, prefix it with an underscore: `_c` - | -note: the lint level is defined here - --> $DIR/log_cfg_unused.rs:2:9 - | -2 | #![deny(unused_variables)] - | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/fail/log_control_flow.rs b/tests/ui/fail/log_control_flow.rs deleted file mode 100644 index 60f6eda..0000000 --- a/tests/ui/fail/log_control_flow.rs +++ /dev/null @@ -1,6 +0,0 @@ -#![feature(stmt_expr_attributes, proc_macro_hygiene)] -#![deny(warnings)] - -fn main() { - emit::info!("Text and {a: return 42}"); -} diff --git a/tests/ui/fail/log_control_flow.stderr b/tests/ui/fail/log_control_flow.stderr deleted file mode 100644 index aa78a53..0000000 --- a/tests/ui/fail/log_control_flow.stderr +++ /dev/null @@ -1,24 +0,0 @@ -error[E0308]: mismatched types - --> fail/log_control_flow.rs:5:28 - | -4 | fn main() { - | - expected `()` because of default return type -5 | emit::info!("Text and {a: return 42}"); - | ^^^^^^^^^^^^ expected `()`, found integer - -error: unreachable call - --> fail/log_control_flow.rs:5:28 - | -5 | emit::info!("Text and {a: return 42}"); - | ^^^^^^^^^^^^ - | | - | unreachable call - | any code following this expression is unreachable - | -note: the lint level is defined here - --> fail/log_control_flow.rs:2:9 - | -2 | #![deny(warnings)] - | ^^^^^^^^ - = note: `#[deny(unreachable_code)]` implied by `#[deny(warnings)]` - = note: this error originates in the macro `emit::ct::__private_capture` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/fail/log_interpolated_unsatisfied_trait_debug.rs b/tests/ui/fail/log_interpolated_unsatisfied_trait_debug.rs deleted file mode 100644 index 1efe0f8..0000000 --- a/tests/ui/fail/log_interpolated_unsatisfied_trait_debug.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![feature(stmt_expr_attributes, proc_macro_hygiene)] - -// Does not implement `Display` -struct Input; - -fn main() { - emit::info!("Text \"and\" {#[emit::as_debug] a: Input} and more"); -} diff --git a/tests/ui/fail/log_interpolated_unsatisfied_trait_debug.stderr b/tests/ui/fail/log_interpolated_unsatisfied_trait_debug.stderr deleted file mode 100644 index a1cc40a..0000000 --- a/tests/ui/fail/log_interpolated_unsatisfied_trait_debug.stderr +++ /dev/null @@ -1,24 +0,0 @@ -error[E0277]: `Input` doesn't implement `std::fmt::Debug` - --> fail/log_interpolated_unsatisfied_trait_debug.rs:7:32 - | -7 | emit::info!("Text \"and\" {#[emit::as_debug] a: Input} and more"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ `Input` cannot be formatted using `{:?}` - | - = help: the trait `std::fmt::Debug` is not implemented for `Input` - = note: add `#[derive(Debug)]` to `Input` or manually `impl std::fmt::Debug for Input` - = help: the following other types implement trait `main::emit::emit_rt::capture::Capture`: - <(dyn std::error::Error + 'static) as main::emit::emit_rt::capture::Capture> - <(dyn std::fmt::Debug + 'static) as main::emit::emit_rt::capture::Capture> - <(dyn std::fmt::Display + 'static) as main::emit::emit_rt::capture::Capture> - > - = note: required for `Input` to implement `main::emit::emit_rt::capture::Capture` -note: required by a bound in `__private_capture_anon_as_debug` - --> $WORKSPACE/rt/src/capture.rs - | - | Self: Capture, - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `__PrivateCapture::__private_capture_anon_as_debug` - = note: this error originates in the macro `emit::ct::__private_capture_anon_as_debug` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider annotating `Input` with `#[derive(Debug)]` - | -4 | #[derive(Debug)] - | diff --git a/tests/ui/fail/log_interpolated_unsatisfied_trait_default.rs b/tests/ui/fail/log_interpolated_unsatisfied_trait_default.rs deleted file mode 100644 index d6d6d6b..0000000 --- a/tests/ui/fail/log_interpolated_unsatisfied_trait_default.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![feature(stmt_expr_attributes, proc_macro_hygiene)] - -// Does not implement `Display` -struct Input; - -fn main() { - emit::info!("Text \"and\" {a: Input} and more"); -} diff --git a/tests/ui/fail/log_interpolated_unsatisfied_trait_default.stderr b/tests/ui/fail/log_interpolated_unsatisfied_trait_default.stderr deleted file mode 100644 index 0695d85..0000000 --- a/tests/ui/fail/log_interpolated_unsatisfied_trait_default.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error[E0277]: `Input` doesn't implement `std::fmt::Display` - --> fail/log_interpolated_unsatisfied_trait_default.rs:7:32 - | -7 | emit::info!("Text \"and\" {a: Input} and more"); - | ^^^^^^^^ `Input` cannot be formatted with the default formatter - | - = help: the trait `std::fmt::Display` is not implemented for `Input` - = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead - = help: the following other types implement trait `main::emit::emit_rt::capture::Capture`: - <(dyn std::error::Error + 'static) as main::emit::emit_rt::capture::Capture> - <(dyn std::fmt::Debug + 'static) as main::emit::emit_rt::capture::Capture> - <(dyn std::fmt::Display + 'static) as main::emit::emit_rt::capture::Capture> - > - = note: required for `Input` to implement `main::emit::emit_rt::capture::Capture` -note: required by a bound in `__private_capture_as_default` - --> $WORKSPACE/rt/src/capture.rs - | - | Self: Capture, - | ^^^^^^^^^^^^^^^^^^^^ required by this bound in `__PrivateCapture::__private_capture_as_default` - = note: this error originates in the macro `emit::ct::__private_capture` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/fail/log_many_refs.rs b/tests/ui/fail/log_many_refs.rs deleted file mode 100644 index 7158631..0000000 --- a/tests/ui/fail/log_many_refs.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![feature(stmt_expr_attributes, proc_macro_hygiene)] - -fn main() { - fn call(v: &&&str) { - emit::info!("Logging with a deeply nested {value: v}"); - emit::info!("Logging with a deeply nested {#[emit::as_display(inspect: true)] value: v}"); - } -} diff --git a/tests/ui/fail/log_many_refs.stderr b/tests/ui/fail/log_many_refs.stderr deleted file mode 100644 index 5ffb564..0000000 --- a/tests/ui/fail/log_many_refs.stderr +++ /dev/null @@ -1,29 +0,0 @@ -error[E0521]: borrowed data escapes outside of function - --> fail/log_many_refs.rs:5:52 - | -4 | fn call(v: &&&str) { - | - - let's call the lifetime of this reference `'1` - | | - | `v` is a reference that is only valid in the function body -5 | emit::info!("Logging with a deeply nested {value: v}"); - | ^^^^^^^^ - | | - | `v` escapes the function body here - | argument requires that `'1` must outlive `'static` - | - = note: this error originates in the macro `emit::ct::__private_capture` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0521]: borrowed data escapes outside of function - --> fail/log_many_refs.rs:5:52 - | -4 | fn call(v: &&&str) { - | - - let's call the lifetime of this reference `'2` - | | - | `v` is a reference that is only valid in the function body -5 | emit::info!("Logging with a deeply nested {value: v}"); - | ^^^^^^^^ - | | - | `v` escapes the function body here - | argument requires that `'2` must outlive `'static` - | - = note: this error originates in the macro `emit::ct::__private_capture` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/fail/log_misplaced_attr.rs b/tests/ui/fail/log_misplaced_attr.rs deleted file mode 100644 index 5055b08..0000000 --- a/tests/ui/fail/log_misplaced_attr.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![feature(stmt_expr_attributes, proc_macro_hygiene)] - -fn main() { - let a = String::from("hello"); - - emit::info!("Some text", value: #[emit::as_display] a); -} diff --git a/tests/ui/fail/log_misplaced_attr.stderr b/tests/ui/fail/log_misplaced_attr.stderr deleted file mode 100644 index 8523c50..0000000 --- a/tests/ui/fail/log_misplaced_attr.stderr +++ /dev/null @@ -1,7 +0,0 @@ -error: the emit attribute macros can only be placed on the outside of a field-value expression - --> fail/log_misplaced_attr.rs:6:37 - | -6 | emit::info!("Some text", value: #[emit::as_display] a); - | ^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the attribute macro `emit::as_display` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/fail/log_no_tpl.rs b/tests/ui/fail/log_no_tpl.rs deleted file mode 100644 index 6213b1f..0000000 --- a/tests/ui/fail/log_no_tpl.rs +++ /dev/null @@ -1,5 +0,0 @@ -extern crate emit; - -fn main() { - emit::info!(to: |_| {}); -} diff --git a/tests/ui/fail/log_no_tpl.stderr b/tests/ui/fail/log_no_tpl.stderr deleted file mode 100644 index 36b3376..0000000 --- a/tests/ui/fail/log_no_tpl.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: parsing failed: missing string template - --> fail/log_no_tpl.rs:4:17 - | -4 | emit::info!(to: |_| {}); - | ^^^^^^^^^^ diff --git a/tests/ui/fail/log_non_error_err.rs b/tests/ui/fail/log_non_error_err.rs deleted file mode 100644 index 5bc4748..0000000 --- a/tests/ui/fail/log_non_error_err.rs +++ /dev/null @@ -1,5 +0,0 @@ -extern crate emit; - -fn main() { - emit::info!("something went wrong ({err: 42})"); -} diff --git a/tests/ui/fail/log_non_error_err.stderr b/tests/ui/fail/log_non_error_err.stderr deleted file mode 100644 index 9c354e7..0000000 --- a/tests/ui/fail/log_non_error_err.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error[E0277]: the trait bound `{integer}: std::error::Error` is not satisfied - --> fail/log_non_error_err.rs:4:41 - | -4 | emit::info!("something went wrong ({err: 42})"); - | ^^^^^^^ the trait `std::error::Error` is not implemented for `{integer}` - | - = help: the following other types implement trait `emit::emit_rt::capture::Capture`: - <(dyn std::error::Error + 'static) as emit::emit_rt::capture::Capture> - <(dyn std::fmt::Debug + 'static) as emit::emit_rt::capture::Capture> - <(dyn std::fmt::Display + 'static) as emit::emit_rt::capture::Capture> - > - = note: required for `{integer}` to implement `emit::emit_rt::capture::Capture` -note: required by a bound in `__private_capture_as_error` - --> $WORKSPACE/rt/src/capture.rs - | - | Self: Capture, - | ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `__PrivateCapture::__private_capture_as_error` - = note: this error originates in the macro `emit::ct::__private_capture` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/fail/log_path_expr.rs b/tests/ui/fail/log_path_expr.rs deleted file mode 100644 index d601d63..0000000 --- a/tests/ui/fail/log_path_expr.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![feature(stmt_expr_attributes, proc_macro_hygiene)] - -struct Data { - a: i32, -} - -fn main() { - let data = Data { - a: 42, - }; - - emit::info!("Logging with a deeply nested {data.a}"); -} diff --git a/tests/ui/fail/log_path_expr.stderr b/tests/ui/fail/log_path_expr.stderr deleted file mode 100644 index 7b9dff0..0000000 --- a/tests/ui/fail/log_path_expr.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: parsing failed: failed to parse `data.a` as a field-value expression - --> fail/log_path_expr.rs:12:48 - | -12 | emit::info!("Logging with a deeply nested {data.a}"); - | ^^^^^^ diff --git a/tests/ui/fail/log_unknown_arg.rs b/tests/ui/fail/log_unknown_arg.rs deleted file mode 100644 index 84c1c8e..0000000 --- a/tests/ui/fail/log_unknown_arg.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![feature(stmt_expr_attributes, proc_macro_hygiene)] - -fn main() { - let v = "Some data"; - - emit::info!(not_an_arg: false, "Logging with a deeply nested {value: v}"); -} diff --git a/tests/ui/fail/log_unknown_arg.stderr b/tests/ui/fail/log_unknown_arg.stderr deleted file mode 100644 index f3035f0..0000000 --- a/tests/ui/fail/log_unknown_arg.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: unexpected field `not_an_arg` - --> fail/log_unknown_arg.rs:6:17 - | -6 | emit::info!(not_an_arg: false, "Logging with a deeply nested {value: v}"); - | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/fail/log_unknown_key.rs b/tests/ui/fail/log_unknown_key.rs deleted file mode 100644 index 86d053a..0000000 --- a/tests/ui/fail/log_unknown_key.rs +++ /dev/null @@ -1,5 +0,0 @@ -extern crate emit; - -fn main() { - emit::info!("something went wrong", x); -} diff --git a/tests/ui/fail/log_unknown_key.stderr b/tests/ui/fail/log_unknown_key.stderr deleted file mode 100644 index b73f6f2..0000000 --- a/tests/ui/fail/log_unknown_key.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error[E0425]: cannot find value `x` in this scope - --> fail/log_unknown_key.rs:4:41 - | -4 | emit::info!("something went wrong", x); - | ^ not found in this scope diff --git a/tests/ui/fail/log_unknown_key_tpl.rs b/tests/ui/fail/log_unknown_key_tpl.rs deleted file mode 100644 index d226ab0..0000000 --- a/tests/ui/fail/log_unknown_key_tpl.rs +++ /dev/null @@ -1,5 +0,0 @@ -extern crate emit; - -fn main() { - emit::info!("something went wrong: {x}"); -} diff --git a/tests/ui/fail/log_unknown_key_tpl.stderr b/tests/ui/fail/log_unknown_key_tpl.stderr deleted file mode 100644 index e18c194..0000000 --- a/tests/ui/fail/log_unknown_key_tpl.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error[E0425]: cannot find value `x` in this scope - --> fail/log_unknown_key_tpl.rs:4:41 - | -4 | emit::info!("something went wrong: {x}"); - | ^ not found in this scope diff --git a/tests/ui/fail/log_unkown_attr_arg.rs b/tests/ui/fail/log_unkown_attr_arg.rs deleted file mode 100644 index 6373ef5..0000000 --- a/tests/ui/fail/log_unkown_attr_arg.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![feature(stmt_expr_attributes, proc_macro_hygiene)] - -fn main() { - let v = "Some data"; - - emit::info!("Logging with a deeply nested {#[emit::as_display(not_an_arg: false)] value: v}"); -} diff --git a/tests/ui/fail/log_unkown_attr_arg.stderr b/tests/ui/fail/log_unkown_attr_arg.stderr deleted file mode 100644 index bd718b7..0000000 --- a/tests/ui/fail/log_unkown_attr_arg.stderr +++ /dev/null @@ -1,7 +0,0 @@ -error: unexpected field `not_an_arg` - --> fail/log_unkown_attr_arg.rs:6:5 - | -6 | emit::info!("Logging with a deeply nested {#[emit::as_display(not_an_arg: false)] value: v}"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `emit::info` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/lib.rs b/tests/ui/lib.rs deleted file mode 100644 index 05c2eec..0000000 --- a/tests/ui/lib.rs +++ /dev/null @@ -1,9 +0,0 @@ -#[cfg(test)] -mod tests { - #[test] - fn ui() { - let t = trybuild::TestCases::new(); - t.pass("pass/*.rs"); - t.compile_fail("fail/*.rs"); - } -} diff --git a/tests/ui/pass/format.rs b/tests/ui/pass/format.rs deleted file mode 100644 index a917491..0000000 --- a/tests/ui/pass/format.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![feature(stmt_expr_attributes, proc_macro_hygiene)] - -fn main() { - let msg = emit::format!("A string {template: 42}"); - - assert_eq!("A string 42", msg); -} diff --git a/tests/ui/pass/log_additional.rs b/tests/ui/pass/log_additional.rs deleted file mode 100644 index ac1d346..0000000 --- a/tests/ui/pass/log_additional.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![feature(stmt_expr_attributes, proc_macro_hygiene)] - -fn main() { - tracing_subscriber::fmt().init(); - - let a = String::from("hello"); - let c = 42; - let e = std::io::Error::from(std::io::ErrorKind::Other); - let f = { - let mut map = std::collections::BTreeMap::new(); - map.insert("a", 42i32); - map.insert("b", 17); - map - }; - - emit::info!("There's no replacements here", - a, - b: 17, - #[emit::as_debug] - c, - d: String::from("short lived!"), - err: e, - #[emit::as_sval] - f, - ); -} diff --git a/tests/ui/pass/log_cfg.rs b/tests/ui/pass/log_cfg.rs deleted file mode 100644 index fe094a5..0000000 --- a/tests/ui/pass/log_cfg.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![feature(stmt_expr_attributes, proc_macro_hygiene)] -#![allow(unused_variables)] - -fn main() { - tracing_subscriber::fmt().init(); - - let a = String::from("hello"); - let c = 42; - - emit::info!("A log with cfgs {#[cfg(disabled)] b: 17}", - a, - #[emit::as_debug] - #[cfg(disabled)] - c, - d: String::from("short lived!"), - ); -} diff --git a/tests/ui/pass/log_custom_target.rs b/tests/ui/pass/log_custom_target.rs deleted file mode 100644 index 6e953c0..0000000 --- a/tests/ui/pass/log_custom_target.rs +++ /dev/null @@ -1,31 +0,0 @@ -#![feature(stmt_expr_attributes, proc_macro_hygiene)] - -extern crate emit; - -#[macro_use] -extern crate serde_derive; - -use uuid::Uuid; - -#[derive(Serialize)] -struct Work { - id: Uuid, - description: String, - size: usize, -} - -impl Work { - pub fn complete(self) {} -} - -fn main() { - let work = Work { - id: Uuid::new_v4(), - description: String::from("upload all the documents"), - size: 1024, - }; - - emit::info!(to: |r| println!("{}", r.msg()), "scheduling background work {description: work.description} ({id: work.id})", #[emit::as_serde] work); - - work.complete(); -} diff --git a/tests/ui/pass/log_err.rs b/tests/ui/pass/log_err.rs deleted file mode 100644 index 953059c..0000000 --- a/tests/ui/pass/log_err.rs +++ /dev/null @@ -1,18 +0,0 @@ -#![feature(stmt_expr_attributes, proc_macro_hygiene)] - -extern crate emit; - -use std::io; - -fn main() { - emit::to(|record| { - // Just make sure there's a typed `std::error::Error` there - let err = record.props().err().expect("missing error"); - - println!("{}", err.downcast_ref::().expect("invalid error type")); - }); - - let err = io::Error::from(io::ErrorKind::Other); - - emit::info!("something went wrong ({err})"); -} diff --git a/tests/ui/pass/log_external.rs b/tests/ui/pass/log_external.rs deleted file mode 100644 index bc049f0..0000000 --- a/tests/ui/pass/log_external.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![feature(stmt_expr_attributes, proc_macro_hygiene)] - -extern crate emit; - -use uuid::Uuid; - -fn main() { - emit::to(|record| { - // Just make sure we can fetch a `Uuid` - let id = record.props().get("id").expect("missing id"); - let id = id.downcast_ref::().expect("not a uuid"); - - println!("{}", id); - }); - - let id = Uuid::new_v4(); - - emit::info!("something went wrong ({id})"); -} diff --git a/tests/ui/pass/log_interpolated.rs b/tests/ui/pass/log_interpolated.rs deleted file mode 100644 index f7d80cb..0000000 --- a/tests/ui/pass/log_interpolated.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![feature(stmt_expr_attributes, proc_macro_hygiene)] - -fn main() { - tracing_subscriber::fmt().init(); - - let a = String::from("hello"); - let c = 42; - let e = std::io::Error::from(std::io::ErrorKind::Other); - let f = { - let mut map = std::collections::BTreeMap::new(); - map.insert("a", 42); - map.insert("b", 17); - map - }; - - emit::info!("Text and {a} and {b: 17} and {#[emit::as_debug] c} or {#[emit::as_display] d: String::from(\"short lived!\")} and {err: e} and {#[emit::as_sval] f}"); -} diff --git a/tests/ui/pass/log_many_ref.rs b/tests/ui/pass/log_many_ref.rs deleted file mode 100644 index c12ea32..0000000 --- a/tests/ui/pass/log_many_ref.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![feature(stmt_expr_attributes, proc_macro_hygiene)] - -fn main() { - tracing_subscriber::fmt().init(); - - fn call(v: &&&str) { - emit::info!("Logging with a deeply nested {value: ***v}"); - emit::info!("Logging with a deeply nested {#[emit::as_display] value: v}"); - } -} diff --git a/tests/ui/pass/log_mixed.rs b/tests/ui/pass/log_mixed.rs deleted file mode 100644 index 55ab5fe..0000000 --- a/tests/ui/pass/log_mixed.rs +++ /dev/null @@ -1,24 +0,0 @@ -#![feature(stmt_expr_attributes, proc_macro_hygiene)] - -fn main() { - tracing_subscriber::fmt().init(); - - let a = String::from("hello"); - let c = 42; - let err = std::io::Error::from(std::io::ErrorKind::Other); - let f = { - let mut map = std::collections::BTreeMap::new(); - map.insert("a", 42); - map.insert("b", 17); - map - }; - - emit::info!("Text and {a} and {b} and {#[emit::as_debug] c} or {d}", - b: 17, - #[emit::as_debug] - d: String::from("short lived!"), - err, - #[emit::as_sval] - f, - ); -} diff --git a/tests/ui/pass/log_non_err.rs b/tests/ui/pass/log_non_err.rs deleted file mode 100644 index 9146257..0000000 --- a/tests/ui/pass/log_non_err.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![feature(stmt_expr_attributes, proc_macro_hygiene)] - -extern crate emit; - -fn main() { - tracing_subscriber::fmt().init(); - - emit::info!("something went wrong ({#[emit::as_display] err: 42})"); -} diff --git a/tests/ui/pass/log_real.rs b/tests/ui/pass/log_real.rs deleted file mode 100644 index 56c322b..0000000 --- a/tests/ui/pass/log_real.rs +++ /dev/null @@ -1,33 +0,0 @@ -#![feature(stmt_expr_attributes, proc_macro_hygiene)] - -#[macro_use] -extern crate serde_derive; - -use uuid::Uuid; - -#[derive(Serialize)] -struct Work { - id: Uuid, - description: String, - size: usize, -} - -impl Work { - pub fn complete(self) {} -} - -fn main() { - tracing_subscriber::fmt().init(); - - let work = Work { - id: Uuid::new_v4(), - description: String::from("upload all the documents"), - size: 1024, - }; - - emit::info!("scheduling background work {description: work.description} ({id: work.id})", #[emit::as_serde] work); - - emit::debug!("executing background work ({id: work.id})"); - - work.complete(); -} diff --git a/tests/ui/pass/log_yak.rs b/tests/ui/pass/log_yak.rs deleted file mode 100644 index 9e6a3ef..0000000 --- a/tests/ui/pass/log_yak.rs +++ /dev/null @@ -1,35 +0,0 @@ -#![feature(stmt_expr_attributes, proc_macro_hygiene)] - -#[derive(Debug)] -pub struct Yak(String); - -impl Yak { - fn shave(&mut self, _: u32) {} -} - -fn find_a_razor() -> Result { - Ok(1) -} - -pub fn shave_the_yak(yak: &mut Yak) { - emit::info!("Commencing yak shaving for {#[emit::as_debug] yak}"); - - loop { - match find_a_razor() { - Ok(razor) => { - emit::info!("Razor located: {razor}"); - yak.shave(razor); - break; - } - Err(err) => { - emit::warn!("Unable to locate a razor: {err}, retrying"); - } - } - } -} - -fn main() { - tracing_subscriber::fmt().init(); - - shave_the_yak(&mut Yak("🐮".to_owned())); -}