1#[derive(Clone, Copy, Debug, Default, Eq, Ord, PartialEq, PartialOrd)]
5pub struct MonotonicDuration(u64);
6
7impl MonotonicDuration {
8 #[must_use]
10 pub const fn new(ticks: u64) -> Self {
11 Self(ticks)
12 }
13
14 #[must_use]
16 pub const fn get(self) -> u64 {
17 self.0
18 }
19}
20
21#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
23pub struct MonotonicInstant(u64);
24
25impl MonotonicInstant {
26 #[must_use]
28 pub const fn new(ticks: u64) -> Self {
29 Self(ticks)
30 }
31
32 #[must_use]
34 pub const fn get(self) -> u64 {
35 self.0
36 }
37
38 pub(crate) const fn checked_duration_since(self, earlier: Self) -> Option<MonotonicDuration> {
39 match self.0.checked_sub(earlier.0) {
40 Some(value) => Some(MonotonicDuration::new(value)),
41 None => None,
42 }
43 }
44
45 pub(crate) const fn checked_add(self, duration: MonotonicDuration) -> Option<Self> {
46 match self.0.checked_add(duration.get()) {
47 Some(value) => Some(Self(value)),
48 None => None,
49 }
50 }
51}