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
use necsim_core::reporter::{boolean::Boolean, FilteredReporter, Reporter};

#[allow(clippy::module_name_repetitions)]
pub trait ReporterContext: core::fmt::Debug {
    type Reporter: Reporter;

    /// # Errors
    ///
    /// Return any error which occured while building the reporter(s)
    fn try_build<KeepSpeciation: Boolean, KeepDispersal: Boolean, KeepProgress: Boolean>(
        self,
    ) -> anyhow::Result<FilteredReporter<Self::Reporter, KeepSpeciation, KeepDispersal, KeepProgress>>;
}

#[allow(clippy::module_name_repetitions)]
pub trait FinalisableReporter {
    fn finalise(self);
}

#[allow(clippy::module_name_repetitions)]
pub struct OpaqueFinalisableReporter<R: Reporter> {
    reporter: R,
}

impl<R: Reporter> OpaqueFinalisableReporter<R> {
    #[must_use]
    pub fn new(reporter: R) -> Self {
        Self { reporter }
    }
}

impl<R: Reporter> From<R> for OpaqueFinalisableReporter<R> {
    fn from(reporter: R) -> Self {
        Self::new(reporter)
    }
}

impl<R: Reporter> FinalisableReporter for OpaqueFinalisableReporter<R> {
    fn finalise(self) {
        self.reporter.finalise();
    }
}