mock_instant 0.1.0

a simple way to mock an std::time::Instant
Documentation

mock_instant

mock_instant

This crate allows you to test Instant/Duration code, deterministically per thread.const

It provides a replacement std::time::Instant that uses a deterministic thread-local 'clock'

You can swap out the std::time::Instant with this one by doing something similar to:

#[cfg(feature = "test-time")]
use mock_instant::Instant;

#[cfg(not(feature = "test-time"))]
use std::time::Instant;

Example

use std::time::Duration;

let now = Instant::now();
MockClock::advance(Duration::from_secs(15));
MockClock::advance(Duration::from_secs(2));

// its been '17' seconds
assert_eq!(now.elapsed(), Duration::from_secs(17));

License: 0BSD