use crate::types::Timestamp;
pub trait Clock {
fn now(&self) -> Timestamp;
}
#[cfg(test)]
mod tests {
use super::Clock;
use crate::types::Timestamp;
struct FixedClock(Timestamp);
impl Clock for FixedClock {
fn now(&self) -> Timestamp {
self.0
}
}
#[test]
fn a_port_implementation_needs_no_host_clock() {
let clock = FixedClock(Timestamp::from_unix_nanos(1_758_412_800_123_456_789));
assert_eq!(clock.now().as_unix_nanos(), 1_758_412_800_123_456_789);
}
#[test]
fn two_reads_of_a_fixed_clock_span_no_time() {
let clock = FixedClock(Timestamp::from_unix_nanos(42));
let first = clock.now();
let second = clock.now();
assert_eq!(second.duration_since(first).map(|d| d.as_nanos()), Some(0));
}
}