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

Commit

Permalink
start cutting back to core API
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus committed Jan 9, 2024
1 parent 9d0ea8b commit 3d0dfc2
Show file tree
Hide file tree
Showing 59 changed files with 222 additions and 1,231 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ members = [
"targets/otlp/gen",
"macros",
"benchmark",
"tests/ui",
]
exclude = [
"tests/smoke-test"
Expand Down
16 changes: 8 additions & 8 deletions core/src/ambient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,26 @@ impl<TEmitter, TFilter: Filter, TCtxt, TClock, TIdGen> Filter
impl<TEmitter, TFilter, TCtxt: Ctxt, TClock, TIdGen> Ctxt
for Ambient<TEmitter, TFilter, TCtxt, TClock, TIdGen>
{
type CurrentProps = TCtxt::CurrentProps;
type LocalFrame = TCtxt::LocalFrame;
type Props = TCtxt::Props;
type Frame = TCtxt::Frame;

fn open<P: Props>(&self, props: P) -> Self::LocalFrame {
fn open<P: Props>(&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<F: FnOnce(&Self::CurrentProps)>(&self, with: F) {
fn with_current<F: FnOnce(&Self::Props)>(&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)
}
}
Expand Down Expand Up @@ -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,
{
Expand Down
118 changes: 59 additions & 59 deletions core/src/ctxt.rs
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
use crate::{empty::Empty, props::Props};

pub trait Ctxt {
type CurrentProps: Props + ?Sized;
type LocalFrame;
type Props: Props + ?Sized;
type Frame;

fn open<P: Props>(&self, props: P) -> Self::LocalFrame;
fn open<P: Props>(&self, props: P) -> Self::Frame;

fn enter(&self, local: &mut Self::LocalFrame);
fn enter(&self, local: &mut Self::Frame);

fn with_current<F: FnOnce(&Self::CurrentProps)>(&self, with: F);
fn with_current<F: FnOnce(&Self::Props)>(&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<Self> {
ByRef(self)
}
}

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<P: Props>(&self, props: P) -> Self::LocalFrame {
fn open<P: Props>(&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<F: FnOnce(&Self::CurrentProps)>(&self, with: F) {
fn with_current<F: FnOnce(&Self::Props)>(&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<C: Ctxt> Ctxt for Option<C> {
type CurrentProps = Option<internal::Slot<C::CurrentProps>>;
type LocalFrame = Option<C::LocalFrame>;
type Props = Option<internal::Slot<C::Props>>;
type Frame = Option<C::Frame>;

fn with_current<F: FnOnce(&Self::CurrentProps)>(&self, with: F) {
fn with_current<F: FnOnce(&Self::Props)>(&self, with: F) {
match self {
Some(ctxt) => {
ctxt.with_current(|props| unsafe { with(&Some(internal::Slot::new(props))) })
Expand All @@ -57,23 +57,23 @@ impl<C: Ctxt> Ctxt for Option<C> {
}
}

fn open<P: Props>(&self, props: P) -> Self::LocalFrame {
fn open<P: Props>(&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)
}
Expand All @@ -82,75 +82,75 @@ impl<C: Ctxt> Ctxt for Option<C> {

#[cfg(feature = "alloc")]
impl<'a, C: Ctxt + ?Sized + 'a> Ctxt for alloc::boxed::Box<C> {
type CurrentProps = C::CurrentProps;
type LocalFrame = C::LocalFrame;
type Props = C::Props;
type Frame = C::Frame;

fn with_current<F: FnOnce(&Self::CurrentProps)>(&self, with: F) {
fn with_current<F: FnOnce(&Self::Props)>(&self, with: F) {
(**self).with_current(with)
}

fn open<P: Props>(&self, props: P) -> Self::LocalFrame {
fn open<P: Props>(&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)
}
}

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<P: Props>(&self, props: P) -> Self::LocalFrame {
fn open<P: Props>(&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<F: FnOnce(&Self::CurrentProps)>(&self, with: F) {
fn with_current<F: FnOnce(&Self::Props)>(&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<F: FnOnce(&Self::CurrentProps)>(&self, with: F) {
fn with_current<F: FnOnce(&Self::Props)>(&self, with: F) {
with(&Empty)
}

fn open<P: Props>(&self, _: P) -> Self::LocalFrame {
fn open<P: Props>(&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 {
Expand Down Expand Up @@ -246,11 +246,11 @@ mod alloc_support {

pub trait ErasedCtxt: internal::SealedCtxt {}

impl<C: Ctxt> ErasedCtxt for C where C::LocalFrame: Send + 'static {}
impl<C: Ctxt> ErasedCtxt for C where C::Frame: Send + 'static {}

impl<C: Ctxt> 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)
Expand All @@ -259,7 +259,7 @@ mod alloc_support {

impl<C: Ctxt> 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| {
Expand Down Expand Up @@ -291,55 +291,55 @@ 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<F: FnOnce(&Self::CurrentProps)>(&self, with: F) {
fn with_current<F: FnOnce(&Self::Props)>(&self, with: F) {
let mut f = Some(with);

self.erase_ctxt().0.dispatch_with_current(&mut |props| {
f.take().expect("called multiple times")(&props)
});
}

fn open<P: Props>(&self, props: P) -> Self::LocalFrame {
fn open<P: Props>(&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 = <dyn ErasedCtxt + 'a as Ctxt>::CurrentProps;
type LocalFrame = <dyn ErasedCtxt + 'a as Ctxt>::LocalFrame;
type Props = <dyn ErasedCtxt + 'a as Ctxt>::Props;
type Frame = <dyn ErasedCtxt + 'a as Ctxt>::Frame;

fn with_current<F: FnOnce(&Self::CurrentProps)>(&self, with: F) {
fn with_current<F: FnOnce(&Self::Props)>(&self, with: F) {
(self as &(dyn ErasedCtxt + 'a)).with_current(with)
}

fn open<P: Props>(&self, props: P) -> Self::LocalFrame {
fn open<P: Props>(&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)
}
}
Expand Down
1 change: 0 additions & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 3d0dfc2

Please sign in to comment.