pub trait LogClock: Send + Sync {
fn now_ms(&self) -> u64;
}
#[derive(Debug, Default, Clone, Copy)]
pub struct SystemLogClock;
impl LogClock for SystemLogClock {
fn now_ms(&self) -> u64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|duration| duration.as_millis().try_into().unwrap_or(u64::MAX))
.unwrap_or_default()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FixedLogClock(u64);
impl FixedLogClock {
pub const fn new(timestamp_ms: u64) -> Self {
Self(timestamp_ms)
}
}
impl LogClock for FixedLogClock {
fn now_ms(&self) -> u64 {
self.0
}
}