mio_timer/lib.rs
1mod timer;
2
3pub use timer::{Builder, Timeout, Timer};
4
5mod convert {
6 use std::time::Duration;
7
8 const NANOS_PER_MILLI: u32 = 1_000_000;
9 const MILLIS_PER_SEC: u64 = 1_000;
10
11 /// Convert a `Duration` to milliseconds, rounding up and saturating at
12 /// `u64::MAX`.
13 ///
14 /// The saturating is fine because `u64::MAX` milliseconds are still many
15 /// million years.
16 pub fn millis(duration: Duration) -> u64 {
17 // Round up.
18 let millis = (duration.subsec_nanos() + NANOS_PER_MILLI - 1) / NANOS_PER_MILLI;
19 duration
20 .as_secs()
21 .saturating_mul(MILLIS_PER_SEC)
22 .saturating_add(u64::from(millis))
23 }
24}