Skip to main content

Clock

Trait Clock 

Source
pub trait Clock {
    // Required method
    fn now(&mut self) -> Now;
}
Expand description

A source of monotonic (and optionally wall-clock) time.

Implementations live in adapters — never in protocol or orchestrator crates, which receive Now from their caller instead.

now() takes &mut self so implementations can cache or correct state, such as latching a monotonic floor over a clock that can step backwards.

§Contract

  • monotonic_ms never decreases across successive calls, and saturates at Now::MAX_MONOTONIC_MS rather than reaching the reserved u64::MAX.
  • unix_seconds is None whenever no usable wall-clock reading is available — either the platform has no wall clock, or its clock reads before the Unix epoch. An implementation must not fabricate one from monotonic time.

Required Methods§

Source

fn now(&mut self) -> Now

Samples the current time.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<C: Clock + ?Sized> Clock for &mut C

Source§

fn now(&mut self) -> Now

Implementors§