pub trait Clock: Send + Sync {
// Required methods
fn now(&self) -> String;
fn raise_floor(&self, floor: SystemTime);
}Expand description
Trait defining the clock interface for timestamp generation. CONTRACT: successive calls return strictly increasing values, even across application restarts and NTP corrections.
Required Methods§
Sourcefn now(&self) -> String
fn now(&self) -> String
Returns the current timestamp as ISO-8601 UTC string (e.g. “YYYY-MM-DDTHH:MM:SS.ffffffZ”).
Sourcefn raise_floor(&self, floor: SystemTime)
fn raise_floor(&self, floor: SystemTime)
Raise this clock’s floor to floor, if it is currently behind it.
The contract above is what makes this part of the trait rather than an
implementation detail of SystemClock. “Strictly increasing across
restarts” is not a property a clock can hold on its own — it depends on
what the database already contains, which the clock cannot see. Every
implementation therefore needs a way to be told, and
crate::Database::open_with_clock tells it exactly once, at open.
Without this, injecting a FakeClock was not merely awkward but
unusable on any database with rows in it: a fake starting at the epoch
issues stamps below every existing recorded_at and the first concept
write aborts on trg_concepts_monotonic_ra. That is the reason defect K
stalled for three releases, and it is a missing trait method rather than
a missing constructor argument.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".