pub trait Instant:
Sized
+ Ord
+ Copy
+ Clone
+ Debug
+ Send
+ Sync
+ InspectableValue
+ 'static {
// Required methods
fn checked_duration_since(&self, earlier: Self) -> Option<Duration>;
fn checked_add(&self, duration: Duration) -> Option<Self>;
fn saturating_add(&self, duration: Duration) -> Self;
fn checked_sub(&self, duration: Duration) -> Option<Self>;
// Provided methods
fn saturating_duration_since(&self, earlier: Self) -> Duration { ... }
fn panicking_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 checked_duration_since(&self, earlier: Self) -> Option<Duration>
fn checked_duration_since(&self, earlier: Self) -> Option<Duration>
Returns the amount of time elapsed from another instant to this one.
Returns None
if earlier
is not before self
.
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 saturating_add(&self, duration: Duration) -> Self
fn saturating_add(&self, duration: Duration) -> Self
Returns the instant at self + duration
saturating to the maximum
representable instant value.
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.
Provided Methods§
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 panicking_add(&self, duration: Duration) -> Self
fn panicking_add(&self, duration: Duration) -> Self
Unwraps the result from checked_add
.
§Panics
This function will panic if the addition makes the clock wrap around.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.