nucleus/checkpoint/
state.rs1use crate::error::StateTransition;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum CheckpointState {
6 None,
8 Dumping,
10 Dumped,
12 Restoring,
14 Restored,
16}
17
18impl StateTransition for CheckpointState {
19 fn can_transition_to(&self, next: &CheckpointState) -> bool {
20 matches!(
21 (self, next),
22 (CheckpointState::None, CheckpointState::Dumping)
23 | (CheckpointState::Dumping, CheckpointState::Dumped)
24 | (CheckpointState::Dumping, CheckpointState::None)
25 | (CheckpointState::None, CheckpointState::Restoring)
26 | (CheckpointState::Restoring, CheckpointState::Restored)
27 | (CheckpointState::Restoring, CheckpointState::None)
28 )
29 }
30
31 fn is_terminal(&self) -> bool {
32 false
33 }
34}
35
36#[cfg(test)]
37mod tests {
38 use super::*;
39
40 #[test]
41 fn test_abort_transitions() {
42 let state = CheckpointState::Dumping;
44 assert!(
45 state.can_transition_to(&CheckpointState::None),
46 "Dumping must be able to abort back to None"
47 );
48 let state = CheckpointState::Restoring;
49 assert!(
50 state.can_transition_to(&CheckpointState::None),
51 "Restoring must be able to abort back to None"
52 );
53 }
54}