113 lines
2.5 KiB
Rust
113 lines
2.5 KiB
Rust
//! Structures for tracing the execution flow of [Monad]s.
|
|
|
|
mod rendered;
|
|
mod rendered_display;
|
|
mod trace;
|
|
mod traceable;
|
|
mod traced;
|
|
|
|
use crate::rcore::*;
|
|
|
|
use super::*;
|
|
|
|
pub use self::rendered::{
|
|
RenderedAny, RenderedCommon, RenderedLong, RenderedWide, WithLengthAndWidth,
|
|
};
|
|
use self::trace::*;
|
|
pub use self::traceable::Traceable;
|
|
pub use self::traced::Traced;
|
|
|
|
/// [`Diagnostic`] for [Traced] objects.
|
|
///
|
|
/// [`Diagnostic::after`]/[`Diagnostic::before`] are represented in [`RenderedCommon::Event`].
|
|
/// [`Diagnostic::wrapped`] is represented in [`RenderedCommon::Action`].
|
|
pub struct TracedDiagnostic;
|
|
|
|
/// Implementation of [`Monad`] for [Traced] objects.
|
|
pub type TracedInstance = instances::effect::EffectInstance<TraceBox>;
|
|
|
|
impl instances::effect::Effect for TraceBox {
|
|
fn e_pure() -> Self {
|
|
TraceBox::pure()
|
|
}
|
|
|
|
fn e_seq(el: Self, er: Self) -> Self {
|
|
TraceBox::parallel(el, er)
|
|
}
|
|
|
|
fn e_after(self, effect: Self) -> Self {
|
|
self.after(effect)
|
|
}
|
|
}
|
|
|
|
trait WithTrace: Sized {
|
|
fn with_trace(self, t: TraceBox) -> Traced<Self>;
|
|
}
|
|
|
|
impl<A> WithTrace for A {
|
|
fn with_trace(self, t: TraceBox) -> Traced<Self> {
|
|
Traced {
|
|
value: self,
|
|
effect: t,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<A> Traced<A> {
|
|
fn wrapped(self, event: String) -> Self {
|
|
Traced {
|
|
value: self.value,
|
|
effect: self.effect.wrapped(event),
|
|
}
|
|
}
|
|
|
|
pub fn after_resolution(self) -> Self {
|
|
self.after(TraceBox::resolution())
|
|
}
|
|
|
|
fn after(self, t: TraceBox) -> Self {
|
|
Traced {
|
|
value: self.value,
|
|
effect: self.effect.after(t),
|
|
}
|
|
}
|
|
|
|
fn before(self, t: TraceBox) -> Self {
|
|
Traced {
|
|
value: self.value,
|
|
effect: self.effect.before(t),
|
|
}
|
|
}
|
|
|
|
pub fn length(&self) -> usize {
|
|
self.effect.length()
|
|
}
|
|
|
|
pub fn width(&self) -> usize {
|
|
self.effect.width()
|
|
}
|
|
}
|
|
|
|
impl<'a> Diagnostic<'a, TracedInstance> for TracedDiagnostic {
|
|
fn after<'b, A>(fa: Traced<A>, event: impl FnOnce() -> String) -> Traced<A>
|
|
where
|
|
'a: 'b,
|
|
{
|
|
fa.after(TraceBox::event(event()))
|
|
}
|
|
|
|
fn before<'b, A>(fa: Traced<A>, event: impl FnOnce() -> String) -> Traced<A>
|
|
where
|
|
'a: 'b,
|
|
{
|
|
fa.before(TraceBox::event(event()))
|
|
}
|
|
|
|
fn wrapped<'b, A>(fa: Traced<A>, event: impl FnOnce() -> String) -> Traced<A>
|
|
where
|
|
'a: 'b,
|
|
{
|
|
fa.wrapped(event())
|
|
}
|
|
}
|