Trait governor::clock::Reference [−][src]
pub trait Reference: Sized + Add<Nanos, Output = Self> + PartialEq + Eq + Ord + Copy + Clone + Send + Sync + Debug {
fn duration_since(&self, earlier: Self) -> Nanos;
fn saturating_sub(&self, duration: Nanos) -> Self;
}
Expand description
A measurement from a clock.
Required methods
fn duration_since(&self, earlier: Self) -> Nanos
fn duration_since(&self, earlier: Self) -> Nanos
Determines the time that separates two measurements of a
clock. Implementations of this must perform a saturating
subtraction - if the earlier
timestamp should be later,
duration_since
must return the zero duration.
fn saturating_sub(&self, duration: Nanos) -> Self
fn saturating_sub(&self, duration: Nanos) -> Self
Returns a reference point that lies at most duration
in the
past from the current reference. If an underflow should occur,
returns the current reference.
Implementations on Foreign Types
The internal duration between this point and another.
let diff = Duration::from_secs(20).duration_since(Duration::from_secs(10));
assert_eq!(diff, Duration::from_secs(10).into());
The internal duration between this point and another.
let diff = Reference::saturating_sub(&Duration::from_secs(20), Duration::from_secs(10).into());
assert_eq!(diff, Duration::from_secs(10));
Returns the difference in times between the two SystemTimes. Due to the fallible nature of SystemTimes, returns the zero duration if a negative duration would result (e.g. due to system clock adjustments).