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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use core::marker::PhantomData;

use crate::cogs::{
    backup::BackedUp, ActiveLineageSampler, Backup, CoalescenceSampler, DispersalSampler,
    EmigrationExit, EventSampler, Habitat, ImmigrationEntry, LineageStore, MathsCore, RngCore,
    SpeciationProbability, TurnoverRate,
};

use super::Simulation;

#[contract_trait]
impl<
        M: MathsCore,
        H: Habitat<M>,
        G: RngCore<M>,
        S: LineageStore<M, H>,
        X: EmigrationExit<M, H, G, S>,
        D: DispersalSampler<M, H, G>,
        C: CoalescenceSampler<M, H, S>,
        T: TurnoverRate<M, H>,
        N: SpeciationProbability<M, H>,
        E: EventSampler<M, H, G, S, X, D, C, T, N>,
        I: ImmigrationEntry<M>,
        A: ActiveLineageSampler<M, H, G, S, X, D, C, T, N, E, I>,
    > Backup for Simulation<M, H, G, S, X, D, C, T, N, E, I, A>
{
    unsafe fn backup_unchecked(&self) -> Self {
        Simulation {
            maths: PhantomData::<M>,
            habitat: self.habitat.backup_unchecked(),
            lineage_store: self.lineage_store.backup_unchecked(),
            emigration_exit: self.emigration_exit.backup_unchecked(),
            dispersal_sampler: self.dispersal_sampler.backup_unchecked(),
            coalescence_sampler: self.coalescence_sampler.backup_unchecked(),
            turnover_rate: self.turnover_rate.backup_unchecked(),
            speciation_probability: self.speciation_probability.backup_unchecked(),
            event_sampler: self.event_sampler.backup_unchecked(),
            active_lineage_sampler: self.active_lineage_sampler.backup_unchecked(),
            rng: self.rng.backup_unchecked(),
            immigration_entry: self.immigration_entry.backup_unchecked(),
            migration_balance: self.migration_balance,
        }
    }
}

impl<
        M: MathsCore,
        H: Habitat<M>,
        G: RngCore<M>,
        S: LineageStore<M, H>,
        X: EmigrationExit<M, H, G, S>,
        D: DispersalSampler<M, H, G>,
        C: CoalescenceSampler<M, H, S>,
        T: TurnoverRate<M, H>,
        N: SpeciationProbability<M, H>,
        E: EventSampler<M, H, G, S, X, D, C, T, N>,
        I: ImmigrationEntry<M>,
        A: ActiveLineageSampler<M, H, G, S, X, D, C, T, N, E, I>,
    > BackedUp<Simulation<M, H, G, S, X, D, C, T, N, E, I, A>>
{
    pub fn resume(&self) -> Simulation<M, H, G, S, X, D, C, T, N, E, I, A> {
        unsafe {
            Simulation {
                maths: PhantomData::<M>,
                habitat: self.0.habitat.backup_unchecked(),
                lineage_store: self.0.lineage_store.backup_unchecked(),
                emigration_exit: self.0.emigration_exit.backup_unchecked(),
                dispersal_sampler: self.0.dispersal_sampler.backup_unchecked(),
                coalescence_sampler: self.0.coalescence_sampler.backup_unchecked(),
                turnover_rate: self.0.turnover_rate.backup_unchecked(),
                speciation_probability: self.0.speciation_probability.backup_unchecked(),
                event_sampler: self.0.event_sampler.backup_unchecked(),
                active_lineage_sampler: self.0.active_lineage_sampler.backup_unchecked(),
                rng: self.0.rng.backup_unchecked(),
                immigration_entry: self.0.immigration_entry.backup_unchecked(),
                migration_balance: self.0.migration_balance,
            }
        }
    }
}