event_simulation/
dynamic.rs1use std::ops::Deref;
2
3use crate::{Editable, SimulationInfo};
4
5pub enum DynamicSimulation<S: SimulationInfo, E: Editable> {
7 Default(S),
9 Simulated(E),
11}
12
13impl<S: SimulationInfo, E: Editable> DynamicSimulation<S, E> {
14 pub fn default(&self) -> Option<&S> {
16 if let Self::Default(info) = self {
17 Some(info)
18 } else {
19 None
20 }
21 }
22 pub fn default_mut(&mut self) -> Option<&mut S> {
24 if let Self::Default(info) = self {
25 Some(info)
26 } else {
27 None
28 }
29 }
30 pub fn simulated(&self) -> Option<&E> {
32 if let Self::Simulated(sim) = self {
33 Some(sim)
34 } else {
35 None
36 }
37 }
38 pub fn simulated_mut(&mut self) -> Option<&mut E> {
40 if let Self::Simulated(sim) = self {
41 Some(sim)
42 } else {
43 None
44 }
45 }
46}
47
48impl<S: SimulationInfo, E: Editable + Deref<Target = S>> Deref for DynamicSimulation<S, E> {
49 type Target = S;
50 fn deref(&self) -> &S {
51 match self {
52 Self::Default(info) => info,
53 Self::Simulated(sim) => sim,
54 }
55 }
56}
57
58impl<S: SimulationInfo, E: Editable> From<S> for DynamicSimulation<S, E> {
59 fn from(info: S) -> Self {
60 Self::Default(info)
61 }
62}