1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use crate::rstd::inject::*;

use super::*;

struct TracedInject;

impl<'a, Ctx: Context<'a, _Tm = TracedInstance>> Inject<'a, Ctx> for TracedInject {
    fn inject<A: 'a + Send>(&self, fa: Wrapped<'a, Ctx, A>) -> Wrapped<'a, Ctx, A> {
        fa.after_resolution()
    }
}

/// Extension trait to trace the evaluation flow.
pub trait Traceable<'a, Ctx: Context<'a, _Tm = TracedInstance>>:
    Mentionable<'a, Ctx> + Sized
{
    /// Re-cast the value, adding an extra[^extra]
    /// note ([`RenderedCommon::Resolution`]) to the trace on each resolution.
    ///
    /// [^extra]: applying [`Traceable::trace`] multiple times
    /// might affect the trace in undesireable ways
    fn trace(&self) -> ParseResultA<'a, Self> {
        Arc::new(TracedInject).inject_mentionable(self)
    }
}

impl<'a, Ctx: Context<'a, _Tm = TracedInstance>, A: Mentionable<'a, Ctx>> Traceable<'a, Ctx> for A {}