Skip to main content

a3s_runtime/
clock.rs

1use std::time::{SystemTime, UNIX_EPOCH};
2
3pub trait RuntimeClock: Send + Sync {
4    fn now_ms(&self) -> u64;
5}
6
7#[derive(Debug, Default)]
8pub struct SystemRuntimeClock;
9
10impl RuntimeClock for SystemRuntimeClock {
11    fn now_ms(&self) -> u64 {
12        SystemTime::now()
13            .duration_since(UNIX_EPOCH)
14            .unwrap_or_default()
15            .as_millis()
16            .try_into()
17            .unwrap_or(u64::MAX)
18    }
19}