use lib::*;
#[cfg(feature = "std")]
pub type TimeSource = Instant;
#[cfg(not(feature = "std"))]
pub type TimeSource = Duration;
pub trait Relative:
Sized
+ Sub<Duration, Output = Self>
+ Add<Duration, Output = Self>
+ PartialEq
+ Eq
+ Ord
+ Copy
+ Clone
+ Send
+ Sync
+ Debug
{
fn duration_since(&self, earlier: Self) -> Duration;
}
pub trait Absolute: Relative {
fn now() -> Self;
}
#[cfg(feature = "std")]
mod std {
use std::time::{Duration, Instant};
impl super::Relative for Instant {
fn duration_since(&self, earlier: Self) -> Duration {
self.duration_since(earlier)
}
}
impl super::Absolute for Instant {
#[inline]
fn now() -> Self {
Instant::now()
}
}
use std::time::SystemTime;
impl super::Relative for SystemTime {
fn duration_since(&self, earlier: Self) -> Duration {
self.duration_since(earlier)
.unwrap_or_else(|_| Duration::new(0, 0))
}
}
impl super::Absolute for SystemTime {
#[inline]
fn now() -> Self {
SystemTime::now()
}
}
}
impl Relative for Duration {
fn duration_since(&self, earlier: Self) -> Duration {
*self - earlier
}
}