1use core::{ops::Sub, time::Duration};
2
3pub trait InstantProvider<D = Duration>
8where
9 Self: Sub<Self, Output = D> + Clone,
11{
12 fn now() -> Self;
14
15 fn elapsed(&self) -> D {
17 Self::now() - self.clone()
18 }
19}
20
21#[cfg(feature = "std")]
22impl InstantProvider<std::time::Duration> for std::time::Instant {
23 fn now() -> Self {
24 std::time::Instant::now()
25 }
26}
27
28#[cfg(feature = "embassy")]
29impl InstantProvider<embassy_time::Duration> for embassy_time::Instant {
30 fn now() -> Self {
31 embassy_time::Instant::now()
32 }
33}