marque_engine/clock.rs
1//! Clock abstraction for deterministic timestamps in audit records.
2//!
3//! `Engine` uses `dyn Clock` exclusively for `AppliedFix::timestamp`.
4//! Production code injects `SystemClock`; tests inject `FixedClock`
5//! so snapshot tests of audit NDJSON are deterministic.
6
7use std::time::SystemTime;
8
9/// Abstraction over `SystemTime::now()` for testability.
10pub trait Clock: Send + Sync {
11 fn now(&self) -> SystemTime;
12}
13
14/// Production clock — delegates to `SystemTime::now()`.
15pub struct SystemClock;
16
17impl Clock for SystemClock {
18 fn now(&self) -> SystemTime {
19 SystemTime::now()
20 }
21}
22
23/// Test clock — always returns the same instant.
24pub struct FixedClock(SystemTime);
25
26impl FixedClock {
27 /// Construct a fixed clock that always returns `instant`.
28 pub const fn new(instant: SystemTime) -> Self {
29 Self(instant)
30 }
31}
32
33impl Clock for FixedClock {
34 fn now(&self) -> SystemTime {
35 self.0
36 }
37}