pub trait Reference: Sized + Add<Nanos, Output = Self> + PartialEq + Eq + Ord + Copy + Clone + Send + Sync + Debug {
// Required methods
fn duration_since(&self, earlier: Self) -> Nanos;
fn saturating_sub(&self, duration: Nanos) -> Self;
}
Expand description
A measurement from a clock.
Required Methods§
sourcefn 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.
sourcefn 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.
Object Safety§
This trait is not object safe.
Implementations on Foreign Types§
source§impl Reference for Duration
impl Reference for Duration
source§fn duration_since(&self, earlier: Self) -> Nanos
fn duration_since(&self, earlier: Self) -> Nanos
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());
source§fn saturating_sub(&self, duration: Nanos) -> Self
fn saturating_sub(&self, duration: Nanos) -> Self
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));
source§impl Reference for Instant
impl Reference for Instant
fn duration_since(&self, earlier: Self) -> Nanos
fn saturating_sub(&self, duration: Nanos) -> Self
source§impl Reference for SystemTime
impl Reference for SystemTime
source§fn duration_since(&self, earlier: Self) -> Nanos
fn duration_since(&self, earlier: Self) -> Nanos
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).