Trait netstack3_core::Instant
source · pub trait Instant: Sized + Ord + Copy + Clone + Debug + Send + Sync + InspectableValue + 'static {
// Required methods
fn duration_since(&self, earlier: Self) -> Duration;
fn saturating_duration_since(&self, earlier: Self) -> Duration;
fn checked_add(&self, duration: Duration) -> Option<Self>;
fn checked_sub(&self, duration: Duration) -> Option<Self>;
// Provided method
fn add(&self, duration: Duration) -> Self { ... }
}
Expand description
A type representing an instant in time.
Instant
can be implemented by any type which represents an instant in
time. This can include any sort of real-world clock time (e.g.,
[std::time::Instant
]) or fake time such as in testing.
Required Methods§
sourcefn duration_since(&self, earlier: Self) -> Duration
fn duration_since(&self, earlier: Self) -> Duration
Returns the amount of time elapsed from another instant to this one.
§Panics
This function will panic if earlier
is later than self
.
sourcefn saturating_duration_since(&self, earlier: Self) -> Duration
fn saturating_duration_since(&self, earlier: Self) -> Duration
Returns the amount of time elapsed from another instant to this one, saturating at zero.
sourcefn checked_add(&self, duration: Duration) -> Option<Self>
fn checked_add(&self, duration: Duration) -> Option<Self>
Returns Some(t)
where t
is the time self + duration
if t
can be
represented as Instant
(which means it’s inside the bounds of the
underlying data structure), None
otherwise.
sourcefn checked_sub(&self, duration: Duration) -> Option<Self>
fn checked_sub(&self, duration: Duration) -> Option<Self>
Returns Some(t)
where t
is the time self - duration
if t
can be
represented as Instant
(which means it’s inside the bounds of the
underlying data structure), None
otherwise.