laminar_core/checkpoint/
attempt.rs1#[derive(
5 Debug,
6 Clone,
7 Copy,
8 PartialEq,
9 Eq,
10 Hash,
11 serde::Serialize,
12 serde::Deserialize,
13 rkyv::Archive,
14 rkyv::Serialize,
15 rkyv::Deserialize,
16)]
17pub struct CheckpointAttempt {
18 pub epoch: u64,
20 pub checkpoint_id: u64,
22}
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq)]
26pub enum CheckpointAttemptRelation {
27 Exact,
29 Older,
31 Newer,
33 Conflict,
35}
36
37impl CheckpointAttempt {
38 #[must_use]
40 pub const fn new(epoch: u64, checkpoint_id: u64) -> Self {
41 Self {
42 epoch,
43 checkpoint_id,
44 }
45 }
46
47 #[must_use]
49 pub const fn canonical(checkpoint_id: u64) -> Self {
50 Self::new(checkpoint_id, checkpoint_id)
51 }
52
53 #[must_use]
55 pub const fn is_canonical(self) -> bool {
56 self.epoch != 0 && self.epoch == self.checkpoint_id
57 }
58
59 #[must_use]
61 pub const fn relation_to(self, other: Self) -> CheckpointAttemptRelation {
62 if self.epoch == other.epoch && self.checkpoint_id == other.checkpoint_id {
63 CheckpointAttemptRelation::Exact
64 } else if self.epoch < other.epoch && self.checkpoint_id < other.checkpoint_id {
65 CheckpointAttemptRelation::Older
66 } else if self.epoch > other.epoch && self.checkpoint_id > other.checkpoint_id {
67 CheckpointAttemptRelation::Newer
68 } else {
69 CheckpointAttemptRelation::Conflict
70 }
71 }
72}