1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
use std::time::Instant; /// Returns `Instant` values representing the current instant in time. /// /// This allows customizing the source of time which is especially useful for /// testing. pub trait Now { /// Returns an instant corresponding to "now". fn now(&mut self) -> Instant; } /// Returns the instant corresponding to now using a monotonic clock. #[derive(Debug)] pub struct SystemNow(()); impl SystemNow { /// Create a new `SystemNow`. pub fn new() -> SystemNow { SystemNow(()) } } impl Now for SystemNow { fn now(&mut self) -> Instant { Instant::now() } }