1use crate::agent::AgentName;
2use crate::protocol::ProtocolTypes;
3use crate::trace::Trace;
4
5pub trait TraceHelper<A, PT>
6where
7 PT: ProtocolTypes,
8{
9 fn build_named_trace(self) -> (&'static str, Trace<PT>);
10 fn build_trace(self) -> Trace<PT>;
11 fn fn_name(&self) -> &'static str;
12}
13
14impl<PT, F> TraceHelper<(AgentName, AgentName), PT> for F
15where
16 F: Fn(AgentName, AgentName) -> Trace<PT>,
17 PT: ProtocolTypes,
18{
19 fn build_named_trace(self) -> (&'static str, Trace<PT>) {
20 (self.fn_name(), self.build_trace())
21 }
22
23 fn build_trace(self) -> Trace<PT> {
24 let agent_a = AgentName::first();
25 let agent_b = agent_a.next();
26 (self)(agent_a, agent_b)
27 }
28
29 fn fn_name(&self) -> &'static str {
30 std::any::type_name::<F>()
31 }
32}
33
34impl<PT, F> TraceHelper<AgentName, PT> for F
35where
36 F: Fn(AgentName) -> Trace<PT>,
37 PT: ProtocolTypes,
38{
39 fn build_named_trace(self) -> (&'static str, Trace<PT>) {
40 (self.fn_name(), self.build_trace())
41 }
42
43 fn build_trace(self) -> Trace<PT> {
44 let agent_a = AgentName::first();
45
46 (self)(agent_a)
47 }
48
49 fn fn_name(&self) -> &'static str {
50 std::any::type_name::<F>()
51 }
52}
53
54#[macro_export]
62macro_rules! corpus {
63 () => {
64 vec![]
65 };
66
67 ( $( $func:ident : $cond:expr ),* $(,)? ) => {
68 {
69 use $crate::trace_helper::TraceHelper;
70 let mut corpus = vec![];
71
72 $(
73 if $cond {
74 corpus.push(($func.build_trace(), $func.fn_name()));
75 }
76 )*
77
78 corpus
79 }
80 };
81}