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::protocol::ProtocolTypes;
use crate::trace::Trace;

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

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

    fn build_trace(self) -> Trace<PT> {
        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<PT, F> TraceHelper<AgentName, PT> for F
where
    F: Fn(AgentName) -> Trace<PT>,
    PT: ProtocolTypes,
{
    fn build_named_trace(self) -> (&'static str, Trace<PT>) {
        (self.fn_name(), self.build_trace())
    }

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

        (self)(agent_a)
    }

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