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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use crate::agent::AgentName;
use crate::algebra::Matcher;
use crate::trace::Trace;

pub trait TraceHelper<A, M>
where
    M: Matcher,
{
    fn build_named_trace(self) -> (&'static str, Trace<M>);
    fn build_trace(self) -> Trace<M>;
    fn fn_name(&self) -> &'static str;
}

impl<M, F> TraceHelper<(AgentName, AgentName), M> for F
where
    F: Fn(AgentName, AgentName) -> Trace<M>,
    M: Matcher,
{
    fn build_named_trace(self) -> (&'static str, Trace<M>) {
        (self.fn_name(), self.build_trace())
    }

    fn build_trace(self) -> Trace<M> {
        let agent_a = AgentName::first();
        let agent_b = agent_a.next();
        (self)(agent_a, agent_b)
    }

    fn fn_name(&self) -> &'static str {
        std::any::type_name::<F>()
    }
}

impl<M, F> TraceHelper<AgentName, M> for F
where
    F: Fn(AgentName) -> Trace<M>,
    M: Matcher,
{
    fn build_named_trace(self) -> (&'static str, Trace<M>) {
        (self.fn_name(), self.build_trace())
    }

    fn build_trace(self) -> Trace<M> {
        let agent_a = AgentName::first();

        (self)(agent_a)
    }

    fn fn_name(&self) -> &'static str {
        std::any::type_name::<F>()
    }
}