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
use core::{fmt, marker::PhantomData};

use necsim_core::{impl_report, reporter::Reporter};

use necsim_partitioning_core::LocalPartition;

pub struct IgnoreProgressReporterProxy<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> {
    local_partition: &'l mut P,
    _marker: PhantomData<(&'p (), R)>,
}

impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> fmt::Debug
    for IgnoreProgressReporterProxy<'l, 'p, R, P>
{
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        fmt.debug_struct(stringify!(IgnoreProgressReporterProxy))
            .finish()
    }
}

impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> Reporter
    for IgnoreProgressReporterProxy<'l, 'p, R, P>
{
    impl_report!(speciation(&mut self, speciation: MaybeUsed<
        <<P as LocalPartition<'p, R>>::Reporter as Reporter
    >::ReportSpeciation>) {
        self.local_partition.get_reporter().report_speciation(speciation.into());
    });

    impl_report!(dispersal(&mut self, dispersal: MaybeUsed<
        <<P as LocalPartition<'p, R>>::Reporter as Reporter
    >::ReportDispersal>) {
        self.local_partition.get_reporter().report_dispersal(dispersal.into());
    });

    impl_report!(progress(&mut self, _progress: Ignored) {});
}

impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> IgnoreProgressReporterProxy<'l, 'p, R, P> {
    pub fn from(local_partition: &'l mut P) -> Self {
        Self {
            local_partition,
            _marker: PhantomData::<(&'p (), R)>,
        }
    }

    #[inline]
    pub fn report_total_progress(&mut self, remaining: u64) {
        self.local_partition
            .get_reporter()
            .report_progress(&remaining.into());
    }

    pub fn local_partition(&mut self) -> &mut P {
        self.local_partition
    }
}