device_driver_common/instant.rs
1use std::time::Duration;
2
3pub struct Instant {
4 #[cfg(target_family = "wasm")]
5 inner: web_time::Instant,
6 #[cfg(not(target_family = "wasm"))]
7 inner: std::time::Instant,
8}
9
10impl Instant {
11 pub fn now() -> Self {
12 Self {
13 #[cfg(target_family = "wasm")]
14 inner: web_time::Instant::now(),
15 #[cfg(not(target_family = "wasm"))]
16 inner: std::time::Instant::now(),
17 }
18 }
19
20 pub fn elapsed(&self) -> Duration {
21 self.inner.elapsed()
22 }
23}