mio_extras/
lib.rs

1//! Extra components for use with Mio.
2#![deny(missing_docs)]
3extern crate lazycell;
4extern crate mio;
5extern crate slab;
6
7#[macro_use]
8extern crate log;
9
10pub mod channel;
11pub mod timer;
12
13// Conversion utilities
14mod convert {
15    use std::time::Duration;
16
17    const NANOS_PER_MILLI: u32 = 1_000_000;
18    const MILLIS_PER_SEC: u64 = 1_000;
19
20    /// Convert a `Duration` to milliseconds, rounding up and saturating at
21    /// `u64::MAX`.
22    ///
23    /// The saturating is fine because `u64::MAX` milliseconds are still many
24    /// million years.
25    pub fn millis(duration: Duration) -> u64 {
26        // Round up.
27        let millis = (duration.subsec_nanos() + NANOS_PER_MILLI - 1) / NANOS_PER_MILLI;
28        duration
29            .as_secs()
30            .saturating_mul(MILLIS_PER_SEC)
31            .saturating_add(u64::from(millis))
32    }
33}