Skip to main content

Clock

Trait Clock 

Source
pub trait Clock: Send + Sync {
    // Required methods
    fn now(&self) -> Instant;
    fn unix_nanos(&self) -> u64;
}
Expand description

A source of time. Inject this anywhere time is needed.

Required Methods§

Source

fn now(&self) -> Instant

The current monotonic instant (for elapsed-time logic).

Source

fn unix_nanos(&self) -> u64

The current wall-clock time in nanoseconds since the Unix epoch.

Distinct from Clock::now (which is monotonic and meaningless as an absolute time): this is for stamping externally-meaningful timestamps such as OTLP span start/end. Like now, it goes through the seam so it stays deterministic under a ManualClock.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§