pub struct MonotonicClock { /* private fields */ }Expand description
A clock implementation that provides monotonically increasing time.
This clock uses std::time::Instant as its time source, which guarantees
that time always moves forward and is not affected by system time
adjustments (e.g., NTP synchronization, manual changes).
The clock records a base point when created, and all subsequent time queries are calculated relative to this base point.
§Use Cases
- Performance monitoring
- Timeout control
- Measuring time intervals
- Any scenario requiring stable, monotonic time
§Note
This clock is designed for measuring time intervals, not for getting the
“current time” for display purposes. For timezone support, you can wrap it
with Zoned, but this is generally not recommended as
timezone information is not meaningful for interval measurements.
§Thread Safety
This type is completely thread-safe as all fields are immutable after creation.
§Examples
use prism3_clock::{Clock, MonotonicClock};
use std::thread;
use std::time::Duration;
let clock = MonotonicClock::new();
let start = clock.millis();
thread::sleep(Duration::from_millis(100));
let elapsed = clock.millis() - start;
assert!(elapsed >= 100);§Author
Haixing Hu
Implementations§
Source§impl MonotonicClock
impl MonotonicClock
Trait Implementations§
Source§impl Clock for MonotonicClock
impl Clock for MonotonicClock
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 · 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 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