Clock Abstraction

Version 0.1.0 Updated Jun 28, 2026

Monotony exposes a narrow MonotonicClock trait over std::time::Instant. Inject the trait into code that measures durations, so production code can use StdMonotonicClock while tests provide deterministic time.

use std::time::Duration;

use monotony::{MonotonicClock, StdMonotonicClock};

fn measure_elapsed(clock: &dyn MonotonicClock) -> Duration {
    let started_at = clock.now();
    clock.now().duration_since(started_at)
}

let elapsed = measure_elapsed(&StdMonotonicClock);

assert!(elapsed >= Duration::ZERO);