eth clock: init

This commit is contained in:
occheung 2020-09-10 14:34:31 +08:00
parent 1821b55fc1
commit 05b056d273
1 changed files with 19 additions and 0 deletions

19
examples/util/clock.rs Normal file
View File

@ -0,0 +1,19 @@
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()
}
}