time_compat 1.0.2

std::time passthrough, designed to be patched on a per-workspace level to provide alternate workspace-wide time sources
Documentation
  • Coverage
  • 100%
    1 out of 1 items documented1 out of 1 items with examples
  • Size
  • Source code size: 2.12 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.97 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • codysch/stubs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • codysch codyps

Temporal quantification.

Examples:

There are multiple ways to create a new [Duration]:

# use std::time::Duration;
let five_seconds = Duration::from_secs(5);
assert_eq!(five_seconds, Duration::from_millis(5_000));
assert_eq!(five_seconds, Duration::from_micros(5_000_000));
assert_eq!(five_seconds, Duration::from_nanos(5_000_000_000));

let ten_seconds = Duration::from_secs(10);
let seven_nanos = Duration::from_nanos(7);
let total = ten_seconds + seven_nanos;
assert_eq!(total, Duration::new(10, 7));

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());