1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
use std::sync::Arc; pub trait BaseClock: Send + Sync { fn get_time(&self) -> f64; } pub struct SystemClock; impl BaseClock for SystemClock { fn get_time(&self) -> f64 { std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) .unwrap_or_default() .as_secs_f64() } } pub fn system_clock() -> Arc<dyn BaseClock> { Arc::new(SystemClock) }