#[cfg(target_os = "linux")]
pub mod linux;
mod std;
use crate::Instant;
pub use self::std::StdClock;
pub trait Clock: Default {
fn now(&self) -> Instant;
}
#[cfg(not(target_os = "linux"))]
pub type DefaultClock = StdClock;
#[cfg(target_os = "linux")]
pub type DefaultClock = linux::BootTimeClock;
#[cfg(test)]
pub(crate) mod tests {
use super::*;
use crate::{Clock, Duration, Instant};
pub(crate) fn generic_clock_test<C: Clock>() {
let clock = C::default();
let t1 = clock.now();
assert!(t1 >= Instant::EPOCH);
assert!(t1 < Instant::SOMEDAY);
let t2 = clock.now();
assert!(t2 >= t1);
assert!(t2 < Instant::SOMEDAY);
::std::thread::sleep(::std::time::Duration::from_millis(2));
let t3 = clock.now();
assert!(t3 > t2 + Duration::MILLISECOND);
assert!(t3 < Instant::SOMEDAY);
}
#[test]
fn default_clock() {
generic_clock_test::<DefaultClock>();
}
}