Skip to main content

soaprs_core/
clock.rs

1//! Externally supplied time for deterministic application services.
2
3use std::time::SystemTime;
4
5/// Supplies wall-clock time without making core services read the system clock.
6///
7/// Production runtimes can implement this trait with `SystemTime::now`, while
8/// tests use a fixed or manually advanced clock.
9pub trait Clock: Send + Sync {
10    /// Returns the current wall-clock time.
11    fn now(&self) -> SystemTime;
12}
13
14impl<F> Clock for F
15where
16    F: Fn() -> SystemTime + Send + Sync,
17{
18    fn now(&self) -> SystemTime {
19        self()
20    }
21}