Skip to main content

Clock

Trait Clock 

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

A monotonic clock.

Neither fallible nor async: reading a counter does not wait. Takes &self, so one clock can be shared; an implementation with state uses interior mutability. Code that holds a clock across an .await in a task spawned on a multi-threaded executor needs it to be Sync as well (C: Clock + Sync), so such a clock keeps its state in an atomic or a lock, not a Cell.

Resolution is the implementation’s, and it documents it. The TMDS bring-up procedures (spiritlevel) wait and poll in steps of 1 ms by default, so a clock of 1 ms or finer keeps their timing as configured; a coarser one is still correct, but the times they report are as coarse as the clock.

Required Methods§

Source

fn now(&self) -> Timestamp

The current time. Never earlier than any time this clock returned before.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§