pub struct RealtimeClock { /* private fields */ }Expand description
A monotonic realtime clock that ensures timestamps always move forward.
Wraps SystemTime but guarantees each now() call returns a timestamp
strictly greater than all previous calls, even if the system clock jumps
backwards. When the clock goes backwards, it increments from the last seen
timestamp by one microsecond.
Implementations§
Source§impl RealtimeClock
impl RealtimeClock
Sourcepub fn with_initial(initial: Microseconds) -> Self
pub fn with_initial(initial: Microseconds) -> Self
Create a realtime clock initialized with a specific timestamp.
Useful for resuming from a persisted state (e.g., last journal entry).
Sourcepub fn now(&self) -> Microseconds
pub fn now(&self) -> Microseconds
Get the current monotonic timestamp in microseconds since Unix epoch.
Returns system time if it moved forward, otherwise returns last seen + 1µs.
Sourcepub fn observe(&self, candidate: Microseconds) -> Microseconds
pub fn observe(&self, candidate: Microseconds) -> Microseconds
Observe an external timestamp and return a monotonic realtime value.
If the provided value is not strictly greater than the last seen timestamp,
returns last_seen + 1us to preserve strict monotonicity.
Sourcepub fn last_seen(&self) -> Microseconds
pub fn last_seen(&self) -> Microseconds
Get the last seen timestamp without advancing the clock.