calandria_sim/simulation/
view.rs1use alloc::collections::BTreeMap;
4
5use crate::{DutyId, Model, Topology};
6
7use super::{DutySnapshot, DutyState, SimulationSnapshot};
8
9#[derive(Clone, Copy, Debug)]
11pub struct SimulationView<'a, M: Model> {
12 model: &'a M,
13 topology: &'a Topology,
14 states: &'a BTreeMap<DutyId, DutyState>,
15 snapshot: SimulationSnapshot,
16}
17
18impl<'a, M: Model> SimulationView<'a, M> {
19 pub(crate) const fn new(
20 model: &'a M,
21 topology: &'a Topology,
22 states: &'a BTreeMap<DutyId, DutyState>,
23 snapshot: SimulationSnapshot,
24 ) -> Self {
25 Self {
26 model,
27 topology,
28 states,
29 snapshot,
30 }
31 }
32
33 pub const fn model(self) -> &'a M {
35 self.model
36 }
37
38 pub const fn topology(self) -> &'a Topology {
40 self.topology
41 }
42
43 pub fn duty(self, duty: DutyId) -> Option<DutySnapshot> {
45 self.states
46 .get(&duty)
47 .copied()
48 .map(|state| DutySnapshot::new(duty, state))
49 }
50
51 pub const fn snapshot(self) -> SimulationSnapshot {
53 self.snapshot
54 }
55}