durable_execution_sdk/state/
replay_status.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9#[repr(u8)]
10pub enum ReplayStatus {
11 Replay = 0,
13 New = 1,
15}
16
17impl ReplayStatus {
18 pub fn is_replay(&self) -> bool {
20 matches!(self, Self::Replay)
21 }
22
23 pub fn is_new(&self) -> bool {
25 matches!(self, Self::New)
26 }
27}
28
29impl From<u8> for ReplayStatus {
30 fn from(value: u8) -> Self {
31 match value {
32 0 => Self::Replay,
33 _ => Self::New,
34 }
35 }
36}
37
38impl From<ReplayStatus> for u8 {
39 fn from(status: ReplayStatus) -> Self {
40 status as u8
41 }
42}
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn test_replay_status_replay() {
50 let status = ReplayStatus::Replay;
51 assert!(status.is_replay());
52 assert!(!status.is_new());
53 }
54
55 #[test]
56 fn test_replay_status_new() {
57 let status = ReplayStatus::New;
58 assert!(!status.is_replay());
59 assert!(status.is_new());
60 }
61
62 #[test]
63 fn test_replay_status_from_u8() {
64 assert_eq!(ReplayStatus::from(0), ReplayStatus::Replay);
65 assert_eq!(ReplayStatus::from(1), ReplayStatus::New);
66 assert_eq!(ReplayStatus::from(2), ReplayStatus::New);
67 }
68
69 #[test]
70 fn test_replay_status_to_u8() {
71 assert_eq!(u8::from(ReplayStatus::Replay), 0);
72 assert_eq!(u8::from(ReplayStatus::New), 1);
73 }
74}