pub struct MonotonicClock { /* private fields */ }Expand description
A monotonic clock measuring milliseconds since it was created.
Backed by std::time::Instant, so it never goes backwards and is immune to
wall-clock adjustments. Requires the std feature.
Implementations§
Source§impl MonotonicClock
impl MonotonicClock
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a clock whose zero point is now.
Examples found in repository?
examples/basic.rs (line 17)
9fn main() {
10 // Deterministic clock for tests / demos.
11 let clock = ManualClock::new(0);
12 println!("manual t = {}", clock.now());
13 clock.advance(1_000);
14 println!("after advance(1000): t = {}", clock.now());
15
16 // Real monotonic clock (milliseconds since creation).
17 let real = MonotonicClock::new();
18 let a = real.now();
19 let b = real.now();
20 println!("monotonic: {a} -> {b} (non-decreasing: {})", b >= a);
21
22 // Any &Clock works wherever a Clock is expected.
23 println!("via trait object: {}", read(&clock));
24}Trait Implementations§
Source§impl Clock for MonotonicClock
Available on crate feature std only.
impl Clock for MonotonicClock
Available on crate feature
std only.Source§impl Clone for MonotonicClock
impl Clone for MonotonicClock
Source§fn clone(&self) -> MonotonicClock
fn clone(&self) -> MonotonicClock
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MonotonicClock
impl Debug for MonotonicClock
Auto Trait Implementations§
impl Freeze for MonotonicClock
impl RefUnwindSafe for MonotonicClock
impl Send for MonotonicClock
impl Sync for MonotonicClock
impl Unpin for MonotonicClock
impl UnsafeUnpin for MonotonicClock
impl UnwindSafe for MonotonicClock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more