lfest/types/
timestamp_ns.rs

1use std::fmt::Display;
2
3use derive_more::{Add, AddAssign, Div, Mul, Sub};
4
5/// The type of a timestamp that is measured in nanoseconds.
6#[derive(
7    Default, Debug, Clone, Copy, PartialEq, PartialOrd, Ord, Eq, Add, Sub, Div, AddAssign, Mul,
8)]
9#[div(forward)]
10#[mul(forward)]
11pub struct TimestampNs(i64);
12
13impl From<i64> for TimestampNs {
14    fn from(value: i64) -> Self {
15        Self(value)
16    }
17}
18
19impl From<TimestampNs> for i64 {
20    fn from(val: TimestampNs) -> Self {
21        val.0
22    }
23}
24
25impl Display for TimestampNs {
26    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27        write!(f, "{}", self.0)
28    }
29}
30
31impl AsRef<i64> for TimestampNs {
32    fn as_ref(&self) -> &i64 {
33        &self.0
34    }
35}