use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(transparent)]
pub struct SimTime(i64);
impl SimTime {
#[must_use]
pub const fn new(nanos: i64) -> Self {
Self(nanos)
}
#[must_use]
pub const fn value(self) -> i64 {
self.0
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(transparent)]
pub struct StepIndex(u32);
impl StepIndex {
#[must_use]
pub const fn new(step: u32) -> Self {
Self(step)
}
#[must_use]
pub const fn value(self) -> u32 {
self.0
}
}
#[cfg(test)]
mod tests {
use super::{SimTime, StepIndex};
#[test]
fn test_time_newtypes_serialize_as_bare_scalars() {
assert!(matches!(
serde_json::to_string(&SimTime::new(1_750_291_200_000_000_000)).as_deref(),
Ok("1750291200000000000")
));
assert!(matches!(
serde_json::to_string(&StepIndex::new(7)).as_deref(),
Ok("7")
));
}
#[test]
fn test_sim_time_orders_by_inner_nanos() {
assert!(SimTime::new(1) < SimTime::new(2));
assert!(StepIndex::new(0) < StepIndex::new(1));
}
}