A measurement of a monotonically nondecreasing clock. Opaque and useful only with Duration
.
Instants are always guaranteed to be no less than any previously measured instant when created, and are often useful for tasks such as measuring benchmarks or timing how long an operation takes.
Note, however, that instants are not guaranteed to be steady. In other words, each tick of the underlying clock may not be the same length (e.g. some seconds may be longer than others). An instant may jump forwards or experience time dilation (slow down or speed up), but it will never go backwards.
Instants are opaque types that can only be compared to one another. There is no method to get "the number of seconds" from an instant. Instead, it only allows measuring the duration between two instants (or comparing two instants).
The size of an Instant
struct may vary depending on the target operating system.
Methods
Returns the amount of time elapsed from another instant to this one, or zero duration if that instant is later than this one.
Examples
use ;
let instant = now;
let three_secs = from_secs;
sleep .await;
let now = now;
let duration_since = now.duration_since;
Returns the amount of time elapsed since this instant was created, or zero duration if that this instant is in the future.
Examples
use ;
let instant = now;
let three_secs = from_secs;
sleep .await;
let elapsed = instant.elapsed;
Trait Implementations
Compare two values for equality.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Compare two values for inequality.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Compare two values.
Examples
use Ordering;
assert_eq!;
assert_eq!;
assert_eq!;
Tests less than (for self
and other
) and is used by the <
operator.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Tests less than or equal to (for self
and other
) and is used by the <=
operator.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Tests greater than (for self
and other
) and is used by the >
operator.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Tests greater than or equal to (for self
and other
) and is used by the >=
operator.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Compare two values.
Examples
use Ordering;
assert_eq!;
assert_eq!;
assert_eq!;
Return the minimum of two values.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Return the maximum of two values.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Clone the specified value
.
Examples
let a = 42;
let b = a;
let c = a.clone;
a += 1;
assert_eq!;
assert_eq!;
assert_eq!;
Protocols
let $out = value + $b
Add a duration to this instant and return a new instant.
Examples
use ;
let first = now;
let second = first + SECOND;
assert!;
value += $b
Add a duration to this instant and return a new instant.
Examples
use partial_eq;
use ;
let first = now;
let second = first.clone;
second += SECOND;
assert!;
if value == b
Test two instants for partial equality.
Examples
use partial_eq;
use ;
let first = now;
let second = first + SECOND;
assert_eq!;
assert_eq!;
assert_eq!;
if value == b
Test two instants for total equality.
Examples
use eq;
use ;
let first = now;
let second = first + SECOND;
assert_eq!;
assert_eq!;
assert_eq!;
if value < b
Perform a partial ordered comparison between two instants.
Examples
use ;
let first = now;
let second = first + SECOND;
assert!;
assert!;
assert!;
Using explicit functions:
use Ordering;
use partial_cmp;
use ;
let first = now;
let second = first + SECOND;
assert_eq!;
assert_eq!;
assert_eq!;
if value < b
Perform a totally ordered comparison between two instants.
Examples
use Ordering;
use cmp;
use ;
let first = now;
let second = first + SECOND;
assert_eq!;
assert_eq!;
assert_eq!;
format!
Write a debug representation of the instant.
Examples
use Instant;
let now = now;
println!;
let $out = clone
Clone the current instant.
Examples
use ;
let first = now;
let second = first.clone;
second += SECOND;
assert!;