1use std::{iter::Sum, ops::Add};
2
3use crate::simulation::{Simulation, SwissSystem};
4
5mod assess;
6mod basic;
7mod picks;
8mod strength;
9
10pub use assess::AssessReport;
11pub use basic::BasicReport;
12pub use picks::PicksReport;
13pub use strength::StrengthReport;
14
15pub trait Report: Copy + Send + Sum + Sync {
17 fn update(&mut self, ss: &SwissSystem);
19 fn format(&self, sim: &Simulation) -> String;
21}
22
23#[derive(Debug, Clone, Copy, Default)]
25pub struct ReportAll {
26 pub basic: BasicReport,
27 pub strength: StrengthReport,
28 pub picks: PicksReport,
29}
30
31impl Add for ReportAll {
32 type Output = Self;
33
34 fn add(mut self, rhs: Self) -> Self::Output {
35 self.basic = self.basic + rhs.basic;
36 self.strength = self.strength + rhs.strength;
37 self.picks = self.picks + rhs.picks;
38 self
39 }
40}
41
42impl Sum for ReportAll {
43 fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
44 iter.fold(Self::default(), |acc, report| acc + report)
45 }
46}
47
48impl Report for ReportAll {
49 fn update(&mut self, ss: &SwissSystem) {
50 self.basic.update(ss);
51 self.strength.update(ss);
52 self.picks.update(ss);
53 }
54
55 fn format(&self, sim: &Simulation) -> String {
56 format!(
57 "{}\n{}\n{}",
58 self.picks.format(sim),
59 self.basic.format(sim),
60 self.strength.format(sim)
61 )
62 }
63}
64
65#[derive(Debug, Clone, Copy)]
67pub struct NullReport;
68
69impl Sum for NullReport {
70 fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
71 iter.fold(Self, |_, report| std::hint::black_box(report))
72 }
73}
74
75impl Report for NullReport {
76 fn update(&mut self, _ss: &SwissSystem) {
77 *self = std::hint::black_box(Self);
78 }
79
80 fn format(&self, _: &Simulation) -> String {
81 format!("{self:?}")
82 }
83}