Trait canadensis_core::time::Instant
source · [−]pub trait Instant: Debug + Copy + Clone {
type Duration: Duration + Add<Self, Output = Self>;
fn duration_since(&self, other: &Self) -> Self::Duration;
fn overflow_safe_compare(&self, other: &Self) -> Ordering;
}
Expand description
A moment in time relative to some point in the past
This trait defines the basic properties of an instant that UAVCAN requires.
Clock requirements
The clock that generates instants must be monotonic (its instant values never decrease), except that it may overflow when it reaches an implementation-defined maximum time value.
The instant type must be able to correctly calculate the duration between two instants when overflow has happened once. If overflow has happened more than once between two instants, the calculated duration will be too short.
Associated Types
Required methods
fn duration_since(&self, other: &Self) -> Self::Duration
fn duration_since(&self, other: &Self) -> Self::Duration
Calculates the duration between other and self
Overflow
Instants may overflow, leading to other having a greater numerical value than self even if other is really earlier. Implementations of this function must handle this case correctly, assuming that overflow has only happened once between other and self.
To put it another way, if other has a larger numerical value than self, this function must assume that the clock has overflowed once and return a non-negative Duration.
fn overflow_safe_compare(&self, other: &Self) -> Ordering
fn overflow_safe_compare(&self, other: &Self) -> Ordering
Compares this instant and another in a way that works correctly with overflow
This function should compare self and other, but with one additional rule: if other
has a larger value than self but the absolute value of the difference is less than or equal
to half the maximum Instant value, this function must return Ordering::Greater
.