Skip to main content

Clock

Trait Clock 

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

    // Provided methods
    fn now_secs(&self) -> u64 { ... }
    fn now_secs_i64(&self) -> i64 { ... }
}
Expand description

Abstraction over the system clock.

Inject this into any component that needs time-based logic to enable deterministic testing without real-time delays.

Required Methods§

Source

fn now(&self) -> SystemTime

Return the current time.

Provided Methods§

Source

fn now_secs(&self) -> u64

Return the current Unix timestamp in whole seconds.

Equivalent to now().duration_since(UNIX_EPOCH).as_secs().

Source

fn now_secs_i64(&self) -> i64

Return the current Unix timestamp as a signed 64-bit integer.

Safe until the year 292,277,026,596 when u64 overflows i64.

Implementors§