pub(super) use crate::score::energy_state::EnergyRow as ServiceEnergy;
crate::score::energy_state::impl_energy_state! {
#[derive(Debug, Default)]
pub struct ScaphandreState;
}
pub fn monotonic_ms() -> u64 {
use std::sync::OnceLock;
use std::time::Instant;
static EPOCH: OnceLock<Instant> = OnceLock::new();
let epoch = EPOCH.get_or_init(Instant::now);
let elapsed = epoch.elapsed();
#[allow(clippy::cast_possible_truncation)]
{
elapsed.as_millis() as u64
}
}
#[cfg(test)]
mod tests {
use super::monotonic_ms;
#[test]
fn monotonic_ms_increases() {
let a = monotonic_ms();
std::thread::sleep(std::time::Duration::from_millis(2));
let b = monotonic_ms();
assert!(b > a);
}
}