rtps_parser/rtps/utils/
clock.rs

1pub trait TimerConstructor {
2    fn new() -> Self;
3}
4
5pub trait Timer {
6    fn reset(&mut self);
7    fn elapsed(&self) -> std::time::Duration;
8}
9
10#[derive(Debug, PartialEq, Eq)]
11pub struct StdTimer(std::time::Instant);
12
13impl TimerConstructor for StdTimer {
14    fn new() -> Self {
15        Self(std::time::Instant::now())
16    }
17}
18
19impl Timer for StdTimer {
20    fn reset(&mut self) {
21        self.0 = std::time::Instant::now();
22    }
23
24    fn elapsed(&self) -> std::time::Duration {
25        self.0.elapsed()
26    }
27}