Crate floating_duration [] [src]

A small crate which allows combining a Duration's seconds and nanoseconds into seconds, milliseconds and microseconds. Additionally, it allows easy formatting of a Duration for performance measurements.

Conversion to fractional

use std::time::Duration;
use floating_duration::TimeAsFloat;

let duration = Duration::new(4, 123_456_789);

let secs = duration.as_fractional_secs(); // 4.12..
let millis = duration.as_fractional_millis(); // 4_123.45..
let micros = duration.as_fractional_micros(); // 4_123_456.78..

Automatic formatting

use std::time::Instant;
use floating_duration::TimeFormat;


let start = Instant::now();

do_something();

println!("Needed {}", TimeFormat(start.elapsed()));

Output: Needed 12.841µs

Structs

TimeFormat

A formatting newtype for providing a Display implementation. This format is meant to be used for printing performance measurements.

Traits

TimeAsFloat

Trait for providing as_fractional_* methods.