#[cfg(feature = "std")]
mod std_system;
#[cfg(feature = "std")]
mod std_virtual;
#[cfg(all(feature = "std", feature = "chrono04", feature = "tokio1"))]
mod tokio1_chrono04_system;
#[cfg(all(feature = "std", feature = "chrono04", feature = "tokio1"))]
mod tokio1_chrono04_virtual;
mod private;
#[cfg(feature = "std")]
pub use std_system::*;
#[cfg(feature = "std")]
pub use std_virtual::*;
#[cfg(all(feature = "std", feature = "chrono04", feature = "tokio1"))]
pub use tokio1_chrono04_system::*;
#[cfg(all(feature = "std", feature = "chrono04", feature = "tokio1"))]
pub use tokio1_chrono04_virtual::*;
pub trait Clock {
type Instant;
fn now(&self) -> Self::Instant;
}
pub unsafe trait Monotonic: Clock {}
pub trait Scheduler: Clock {
type Timer: Future<Output = ()> + Send;
fn schedule(&self, deadline: <Self as Clock>::Instant) -> Self::Timer;
}
pub trait ErasedScheduler: Clock {
fn erased_schedule(&self, deadline: <Self as Clock>::Instant) -> Box<dyn Future<Output = ()>>;
}
impl<T> ErasedScheduler for T
where
T: Scheduler,
T::Timer: Send + Sync + 'static,
{
fn erased_schedule(&self, deadline: <Self as Clock>::Instant) -> Box<dyn Future<Output = ()>> {
Box::new(self.schedule(deadline))
}
}
#[cfg(feature = "std")]
pub trait StdClock {
fn now_std(&self) -> ::std::time::Instant;
}
#[cfg(feature = "std")]
impl<T> StdClock for T
where
T: Clock<Instant = ::std::time::Instant>,
{
fn now_std(&self) -> ::std::time::Instant {
self.now()
}
}
#[cfg(feature = "std")]
pub trait StdScheduler: StdClock + Scheduler {}
#[cfg(feature = "std")]
impl<T> StdScheduler for T where T: StdClock + Scheduler {}
#[cfg(feature = "std")]
pub trait ErasedStdScheduler: StdClock + ErasedScheduler {}
#[cfg(feature = "std")]
impl<T> ErasedStdScheduler for T where T: StdClock + ErasedScheduler {}
#[cfg(feature = "chrono04")]
pub trait ChronoClock {
fn now_chrono(&self) -> ::chrono04::DateTime<::chrono04::Utc>;
}
#[cfg(feature = "chrono04")]
impl<T> ChronoClock for T
where
T: Clock<Instant = ::chrono04::DateTime<::chrono04::Utc>>,
{
fn now_chrono(&self) -> ::chrono04::DateTime<::chrono04::Utc> {
self.now()
}
}
#[cfg(feature = "chrono04")]
pub trait ChronoScheduler: ChronoClock + Scheduler {}
#[cfg(feature = "chrono04")]
impl<T> ChronoScheduler for T where T: ChronoClock + Scheduler {}
#[cfg(feature = "chrono04")]
pub trait ErasedChronoScheduler: ChronoClock + ErasedScheduler {}
#[cfg(feature = "chrono04")]
impl<T> ErasedChronoScheduler for T where T: ChronoClock + ErasedScheduler {}