pub trait TimeSource:
Send
+ Sync
+ Debug {
// Required methods
fn now(&self) -> Instant;
fn sleep(&self, duration: Duration);
fn today_date(&self) -> NaiveDate;
// Provided method
fn elapsed_since(&self, earlier: Instant) -> Duration { ... }
}Expand description
Abstraction over time-related operations.
This trait allows production code to use real system time while tests can use a controllable mock implementation for fast, deterministic testing.
Required Methods§
Sourcefn sleep(&self, duration: Duration)
fn sleep(&self, duration: Duration)
Sleep for the specified duration.
In tests, this may be a no-op or advance logical time.
Sourcefn today_date(&self) -> NaiveDate
fn today_date(&self) -> NaiveDate
Get today’s date.
Provided Methods§
Sourcefn elapsed_since(&self, earlier: Instant) -> Duration
fn elapsed_since(&self, earlier: Instant) -> Duration
Calculate elapsed time since an earlier instant.