1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use crate::platform::Instant;
use crate::TimeSpan;
use std::ops::Sub;
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct TimeStamp(Instant, TimeSpan);
impl TimeStamp {
pub fn now() -> Self {
TimeStamp(Instant::now(), TimeSpan::zero())
}
}
impl Sub for TimeStamp {
type Output = TimeSpan;
fn sub(self, rhs: TimeStamp) -> TimeSpan {
TimeSpan::from(self.0 - rhs.0) + self.1 - rhs.1
}
}
impl Sub<TimeSpan> for TimeStamp {
type Output = TimeStamp;
fn sub(self, rhs: TimeSpan) -> TimeStamp {
TimeStamp(self.0, self.1 - rhs)
}
}