Module time
Temporal quantification.
Examples
There are multiple ways to create a new [Duration]:
# use Duration;
let five_seconds = from_secs;
assert_eq!;
assert_eq!;
assert_eq!;
let ten_seconds = from_secs;
let seven_nanos = from_nanos;
let total = ten_seconds + seven_nanos;
assert_eq!;
Using Instant to calculate how long a function took to run:
let now = Instant::now();
// Calling a slow function, it may take a while
slow_function();
let elapsed_time = now.elapsed();
println!("Running slow_function() took {} seconds.", elapsed_time.as_secs());
Structs
-
Instant
A measurement of a monotonically nondecreasing clock.
Opaque and useful only with
Duration. - SystemTime A measurement of the system clock, useful for talking to external entities like the file system or other processes.
-
SystemTimeError
An error returned from the
duration_sinceandelapsedmethods onSystemTime, used to learn how far in the opposite direction a system time lies.
Constants
-
UNIX_EPOCH
An anchor in time which can be used to create new
SystemTimeinstances or learn about where in time aSystemTimelies.