From 05b056d273a06b15d2e1c44412fa52a26b7b3f45 Mon Sep 17 00:00:00 2001 From: occheung Date: Thu, 10 Sep 2020 14:34:31 +0800 Subject: [PATCH] eth clock: init --- examples/util/clock.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 examples/util/clock.rs diff --git a/examples/util/clock.rs b/examples/util/clock.rs new file mode 100644 index 0000000..8064950 --- /dev/null +++ b/examples/util/clock.rs @@ -0,0 +1,19 @@ +use smoltcp::time::{Duration, Instant}; +use core::cell::Cell; + +#[derive(Debug)] +pub struct Clock(Cell); + +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() + } +} \ No newline at end of file