pub trait Clock {
fn now_ns(&self) -> u64;
}
#[cfg(feature = "std")]
use std::sync::OnceLock;
#[cfg(feature = "std")]
use std::time::Instant;
#[cfg(feature = "std")]
fn start_instant() -> &'static Instant {
static START: OnceLock<Instant> = OnceLock::new();
START.get_or_init(Instant::now)
}
#[cfg(feature = "std")]
#[derive(Clone, Copy, Debug, Default)]
pub struct StdClock;
#[cfg(feature = "std")]
impl Clock for StdClock {
fn now_ns(&self) -> u64 {
let nanos = start_instant().elapsed().as_nanos();
nanos.min(u64::MAX as u128) as u64
}
}