Skip to main content

sim_expr_tree_core/
stamp.rs

1/// Monotonic namespace revision paired with the logical tick that produced it.
2#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
3pub struct RevisionTick {
4    revision: u64,
5    logical_tick: u64,
6}
7
8impl RevisionTick {
9    /// Create an explicit revision/tick pair.
10    pub fn new(revision: u64, logical_tick: u64) -> Self {
11        Self {
12            revision,
13            logical_tick,
14        }
15    }
16
17    /// The durable revision number.
18    pub fn revision(self) -> u64 {
19        self.revision
20    }
21
22    /// The serialized writer tick.
23    pub fn logical_tick(self) -> u64 {
24        self.logical_tick
25    }
26
27    pub(crate) fn next_after(self) -> Self {
28        Self {
29            revision: self.revision + 1,
30            logical_tick: self.logical_tick + 1,
31        }
32    }
33}
34
35/// Optional wall-clock observation in Unix milliseconds.
36#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
37pub struct WallTimeMs(u64);
38
39impl WallTimeMs {
40    /// Record a Unix-millisecond observation.
41    pub fn new(unix_millis: u64) -> Self {
42        Self(unix_millis)
43    }
44
45    /// Return the observed Unix milliseconds.
46    pub fn unix_millis(self) -> u64 {
47        self.0
48    }
49}
50
51/// Stamp attached to durable namespace records.
52#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
53pub struct Stamp {
54    revision_tick: RevisionTick,
55    wall_time_ms: Option<WallTimeMs>,
56}
57
58impl Stamp {
59    /// Create a stamp from logical and optional wall-clock observations.
60    pub fn new(revision_tick: RevisionTick, wall_time_ms: Option<WallTimeMs>) -> Self {
61        Self {
62            revision_tick,
63            wall_time_ms,
64        }
65    }
66
67    /// The revision/tick pair.
68    pub fn revision_tick(self) -> RevisionTick {
69        self.revision_tick
70    }
71
72    /// The optional wall-clock observation.
73    pub fn wall_time_ms(self) -> Option<WallTimeMs> {
74        self.wall_time_ms
75    }
76}