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

The duration between two instants

This type must be able to represent the difference between the maximum and minimum instant values.

The Duration must also support adding a Duration and Instant to produce an Instant

Required methods

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.

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.

Implementors