Skip to main content

Clock

Trait Clock 

Source
pub trait Clock:
    Named
    + Send
    + Sync {
    // Required method
    fn now(&self) -> Instant;

    // Provided methods
    fn tick(&self, observed: Instant) -> Instant { ... }
    fn unix_secs(&self) -> u64 { ... }
    fn unix_ms(&self) -> u64 { ... }
}
Expand description

Universal clock surface. Implementers supply now(); HLC-aware implementers additionally implement tick(observed).

Required Methods§

Source

fn now(&self) -> Instant

Current instant per this clock’s notion of time.

Provided Methods§

Source

fn tick(&self, observed: Instant) -> Instant

HLC merge: given an observed Instant from elsewhere, return the next local Instant that is strictly after both self.now() AND observed. Default implementation is wall-clock-based; HLC-aware clocks override.

Source

fn unix_secs(&self) -> u64

Unix timestamp in seconds (now().physical_ms / 1000). Provided as a default method so the dozens of SystemTime::now().duration_since(UNIX_EPOCH) idiom sites across the fleet migrate to one typed surface.

Source

fn unix_ms(&self) -> u64

Unix timestamp in milliseconds (now().physical_ms). Synonym of now().physical_ms; exists for symmetry with unix_secs.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§