#[cfg(not(feature="no_std"))]
mod realtime;
#[cfg(not(feature="no_std"))]
pub use realtime::RealtimeNowSource;
mod fake;
pub use fake::*;
use core::{
ops::Deref,
cell::RefCell,
time::Duration,
};
#[cfg_attr(not(feature="no_std"), doc="\
A source of time information for [`Metronome`](struct.Metronome.html) to use. \
For most purposes, [`RealtimeNowSource`](struct.RealtimeNowSource.html) will \
be sufficient. For non-realtime applications (such as rendering \
pre-determined gameplay footage), see \
[`FakeNowSource`](struct.FakeNowSource.html).")]
#[cfg_attr(feature="no_std", doc="\
A source of time information for [`Metronome`](struct.Metronome.html) to use. \
Because you are using the `no_std` feature, you will need to provide your own \
`NowSource` for realtime use. For non-realtime applications (such as \
rendering pre-determined gameplay footage), see \
[`FakeNowSource`](struct.FakeNowSource.html).")]
pub trait NowSource {
type Instant: TemporalSample;
fn now(&mut self) -> Self::Instant;
}
impl<T: Deref<Target=RefCell<N>>, N: NowSource> NowSource for T {
type Instant = N::Instant;
fn now(&mut self) -> N::Instant {
self.borrow_mut().now()
}
}
pub trait TemporalSample : Sized + Clone + PartialOrd + PartialEq {
fn time_since(&self, origin: &Self) -> Option<Duration>;
fn advanced_by(&self, amount: Duration) -> Self;
fn advance_by(&mut self, amount: Duration) {
*self = self.advanced_by(amount);
}
}