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
53
54
55
56
57
58
use crate::event::{DispersalEvent, SpeciationEvent};

mod combinator;
mod filter;
mod group;
mod r#impl;
mod null;

use boolean::Boolean;
use used::MaybeUsed;

pub mod boolean;
pub mod used;

#[allow(clippy::module_name_repetitions)]
pub use combinator::ReporterCombinator;
#[allow(clippy::module_name_repetitions)]
pub use filter::FilteredReporter;
#[allow(clippy::module_name_repetitions)]
pub use null::NullReporter;

pub trait Reporter: core::fmt::Debug {
    type ReportSpeciation: Boolean;
    type ReportDispersal: Boolean;
    type ReportProgress: Boolean;

    fn report_speciation(&mut self, event: &MaybeUsed<SpeciationEvent, Self::ReportSpeciation>);

    fn report_dispersal(&mut self, event: &MaybeUsed<DispersalEvent, Self::ReportDispersal>);

    fn report_progress(&mut self, remaining: &MaybeUsed<u64, Self::ReportProgress>);

    /// This `initialise` hook can be used to commit to make final
    /// initialisation steps which have side effects.
    ///
    /// # Errors
    ///
    /// Return an error `String` iff initialisation failed.
    /// The calling code should take this as a hint to abort.
    fn initialise(&mut self) -> Result<(), alloc::string::String> {
        Ok(())
    }

    fn finalise(self)
    where
        Self: Sized,
    {
        core::mem::drop(self);
    }

    /// # Safety
    ///
    /// This method should not be implemented manually
    //  please - use the`impl_finalise` macro instead.
    unsafe fn finalise_boxed(self: alloc::boxed::Box<Self>) {
        core::mem::drop(self);
    }
}