diff --git a/Cargo.lock b/Cargo.lock index 80ffa8d..d62a228 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,6 +31,11 @@ name = "bitflags" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "cfg-if" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "clap" version = "2.29.2" @@ -99,6 +104,7 @@ version = "0.4.0" dependencies = [ "approx 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.29.2 (registry+https://github.com/rust-lang/crates.io-index)", "colored 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "indicatif 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -416,6 +422,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum approx 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08abcc3b4e9339e33a3d0a5ed15d84a687350c05689d825e0f6655eef9e76a94" "checksum atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8352656fd42c30a0c3c89d26dea01e3b77c0ab2af18230835c15e2e13cd51859" "checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf" +"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" "checksum clap 2.29.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4151c5790817c7d21bbdc6c3530811f798172915f93258244948b93ba19604a6" "checksum clicolors-control 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f84dec9bc083ce2503908cd305af98bd363da6f54bf8d4bf0ac14ee749ad5d1" "checksum colored 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b0aa3473e85a3161b59845d6096b289bb577874cafeaf75ea1b1beaa6572c7fc" diff --git a/Cargo.toml b/Cargo.toml index 7354282..d73556f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ colored = "1.6" indicatif = "0.9" statistical = "0.1" atty = "0.2.2" +cfg-if = "0.1.2" [target.'cfg(not(windows))'.dependencies] libc = "0.2" diff --git a/src/hyperfine/timer/mod.rs b/src/hyperfine/timer/mod.rs index 2e99d37..9fe26bf 100644 --- a/src/hyperfine/timer/mod.rs +++ b/src/hyperfine/timer/mod.rs @@ -2,25 +2,16 @@ mod internal; pub mod wallclocktimer; -#[cfg(not(windows))] -mod unix_timer; - -#[cfg(not(windows))] -pub use self::unix_timer::get_cpu_timer; - -#[cfg(windows)] -mod windows_timer; - -#[cfg(windows)] -pub use self::windows_timer::get_cpu_timer; - -use std::process::Child; - -pub trait Timer -where - Self: TimerStart + TimerStop, -{ +cfg_if! { + if #[cfg(windows)] { + mod windows_timer; + pub use self::windows_timer::get_cpu_timer; + } else { + mod unix_timer; + pub use self::unix_timer::get_cpu_timer; + } } +use std::process::Child; /// Defines start functionality of a timer. pub trait TimerStart { diff --git a/src/main.rs b/src/main.rs index 27e2542..952ab16 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,21 @@ extern crate atty; + +#[macro_use] +extern crate cfg_if; + #[macro_use] extern crate clap; extern crate colored; extern crate indicatif; extern crate statistical; -#[cfg(not(windows))] -extern crate libc; - -#[cfg(windows)] -extern crate winapi; +cfg_if! { + if #[cfg(windows)] { + extern crate winapi; + } else { + extern crate libc; + } +} #[cfg(test)] #[macro_use]