Struct monotonic_clock::MonotonicClock
source · [−]pub struct MonotonicClock { /* private fields */ }Expand description
Monotonic Clock
A monotonic clock that can be anchored to a specific Epoch. The clock is guaranteed to be monotonic, but not necessarily continuous.
Thread safety
The clock is thread safe.
Eventually, we want to have network synchronization, but for now, we just use the system clock. TODO: Add network synchronization.
Example
use monotonic_clock::MonotonicClock;
use std::thread;
use std::time::Duration;
let clock = MonotonicClock::new();
let start = clock.now();
thread::sleep(Duration::from_millis(100));
let end = clock.now();
assert!(end - start >= Duration::from_millis(100));Implementations
sourceimpl MonotonicClock
impl MonotonicClock
sourcepub fn new() -> MonotonicClock
pub fn new() -> MonotonicClock
Create a new monotonic clock.
sourcepub fn resume(&mut self) -> Option<Duration>
pub fn resume(&mut self) -> Option<Duration>
Resumes paused clock. If the clock is not stopped, this does nothing.
sourcepub fn stop(&mut self) -> Option<Duration>
pub fn stop(&mut self) -> Option<Duration>
Stop the clock if it’s running, otherwise does nothing. Returns the duration the clock was running.
sourcepub fn time_as_float(&self) -> f64
pub fn time_as_float(&self) -> f64
Get the now time since the epoch as a float.
sourcepub fn as_float(&self) -> f64
pub fn as_float(&self) -> f64
Get the now time since the epoch as a float.
This is a convenience function for clock_as_float.
It is provided for compatibility with the time crate.
sourcepub fn is_ticking(&self) -> bool
pub fn is_ticking(&self) -> bool
Is the clock running?
Trait Implementations
sourceimpl Clone for MonotonicClock
impl Clone for MonotonicClock
sourcefn clone(&self) -> MonotonicClock
fn clone(&self) -> MonotonicClock
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresourceimpl Debug for MonotonicClock
impl Debug for MonotonicClock
sourceimpl Default for MonotonicClock
impl Default for MonotonicClock
sourceimpl Display for MonotonicClock
impl Display for MonotonicClock
sourceimpl Hash for MonotonicClock
impl Hash for MonotonicClock
sourceimpl Into<Duration> for MonotonicClock
impl Into<Duration> for MonotonicClock
sourceimpl Ord for MonotonicClock
impl Ord for MonotonicClock
sourcefn cmp(&self, other: &MonotonicClock) -> Ordering
fn cmp(&self, other: &MonotonicClock) -> Ordering
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialEq<MonotonicClock> for MonotonicClock
impl PartialEq<MonotonicClock> for MonotonicClock
sourcefn eq(&self, other: &MonotonicClock) -> bool
fn eq(&self, other: &MonotonicClock) -> bool
sourceimpl PartialOrd<MonotonicClock> for MonotonicClock
impl PartialOrd<MonotonicClock> for MonotonicClock
sourcefn partial_cmp(&self, other: &MonotonicClock) -> Option<Ordering>
fn partial_cmp(&self, other: &MonotonicClock) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moreimpl Copy for MonotonicClock
impl Eq for MonotonicClock
impl StructuralEq for MonotonicClock
impl StructuralPartialEq for MonotonicClock
Auto Trait Implementations
impl RefUnwindSafe for MonotonicClock
impl Send for MonotonicClock
impl Sync for MonotonicClock
impl Unpin for MonotonicClock
impl UnwindSafe for MonotonicClock
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more