humpback-dds/examples/util/clock.rs

19 lines
378 B
Rust
Raw Normal View History

2020-09-10 14:34:31 +08:00
use smoltcp::time::{Duration, Instant};
use core::cell::Cell;
#[derive(Debug)]
pub struct Clock(Cell<Instant>);
impl Clock {
pub fn new() -> Clock {
Clock(Cell::new(Instant::from_millis(0)))
}
pub fn advance(&self, duration: Duration) {
self.0.set(self.0.get() + duration)
}
pub fn elapsed(&self) -> Instant {
self.0.get()
}
}