convert to rust edition 2018
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Andrii Radyk · committed by David Peter · parent a6f61a6 · Browse files · 21 files·+72 added−93 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
21 files+72 added−93 removed
- other:+72 added−93 removed
Provenance
- Commit
2d0b048- Tree
59b97d5- Author
Andrii Radyk <ander.ender@gmail.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
a6f61a6
21 files changed+72 added−93 removed
modified:src/hyperfine/export/asciidoc.rs+3 added-3 removed
1 use super::Exporter;2 3-use hyperfine::format::format_duration_value;4-use hyperfine::types::BenchmarkResult;5-use hyperfine::units::Unit;3+use crate::hyperfine::format::format_duration_value;4+use crate::hyperfine::types::BenchmarkResult;5+use crate::hyperfine::units::Unit;6 7 use std::io::Result;8 9 #[derive(Default)]207 unmodified linesmodified:src/hyperfine/export/csv.rs+2 added-2 removed
1 use super::Exporter;2 3-use hyperfine::types::BenchmarkResult;4-use hyperfine::units::Unit;3+use crate::hyperfine::types::BenchmarkResult;4+use crate::hyperfine::units::Unit;5 6 use std::io::{Error, ErrorKind, Result};7 8 use csv::WriterBuilder;20 unmodified linesmodified:src/hyperfine/export/json.rs+3 added-2 removed
1 use super::Exporter;2-use hyperfine::types::BenchmarkResult;3-use hyperfine::units::Unit;2+use crate::hyperfine::types::BenchmarkResult;3+use crate::hyperfine::units::Unit;4 5 use std::io::{Error, ErrorKind, Result};6 7+use serde::*;8 use serde_json::to_vec_pretty;9 10 #[derive(Serialize, Debug)]11 struct HyperfineSummary<'a> {16 unmodified linesmodified:src/hyperfine/export/markdown.rs+3 added-3 removed
1 use super::Exporter;2 3-use hyperfine::format::format_duration_value;4-use hyperfine::types::BenchmarkResult;5-use hyperfine::units::Unit;3+use crate::hyperfine::format::format_duration_value;4+use crate::hyperfine::types::BenchmarkResult;5+use crate::hyperfine::units::Unit;6 7 use std::io::Result;8 9 #[derive(Default)]247 unmodified linesmodified:src/hyperfine/export/mod.rs+4 added-4 removed
9 unmodified lines10 11 use std::fs::File;12 use std::io::{Result, Write};13 14-use hyperfine::types::BenchmarkResult;15-use hyperfine::units::Unit;14+use crate::hyperfine::types::BenchmarkResult;15+use crate::hyperfine::units::Unit;16 17 /// The desired form of exporter to use for a given file.18 #[derive(Clone)]19 pub enum ExportType {16 unmodified lines36 fn serialize(&self, results: &Vec<BenchmarkResult>, unit: Option<Unit>) -> Result<Vec<u8>>;37 }38 39 struct ExporterWithFilename {40- exporter: Box<Exporter>,40+ exporter: Box<dyn Exporter>,41 filename: String,42 }43 44 /// Handles the management of multiple file exporters.10 unmodified lines55 }56 57 /// Add an additional exporter to the ExportManager58 pub fn add_exporter(&mut self, export_type: ExportType, filename: &str) {59- let exporter: Box<Exporter> = match export_type {59+ let exporter: Box<dyn Exporter> = match export_type {60 ExportType::Asciidoc => Box::new(AsciidocExporter::default()),61 ExportType::Csv => Box::new(CsvExporter::default()),62 ExportType::Json => Box::new(JsonExporter::default()),63 ExportType::Markdown => Box::new(MarkdownExporter::default()),22 unmodified linesmodified:src/hyperfine/timer/internal.rs+1 added-1 removed
1-use hyperfine::units::Second;1+use crate::hyperfine::units::Second;2 3 #[derive(Debug, Copy, Clone)]4 pub struct CPUTimes {5 /// Total amount of time spent executing in user mode14 unmodified linesmodified:src/hyperfine/timer/mod.rs+2 added
1 mod internal;2 3 pub mod wallclocktimer;4 5+use cfg_if::cfg_if;6+7 cfg_if! {8 if #[cfg(windows)] {9 mod windows_timer;10 pub use self::windows_timer::get_cpu_timer;18 unmodified linesmodified:src/hyperfine/timer/unix_timer.rs+6 added-3 removed
1 #![cfg(not(windows))]2 3 use super::internal::{CPUInterval, CPUTimes};4-use hyperfine::timer::{TimerStart, TimerStop};5-use hyperfine::units::Second;4+use crate::hyperfine::timer::{TimerStart, TimerStop};5+use crate::hyperfine::units::Second;6 7 use std::mem;8 use std::process::Child;9 10-pub fn get_cpu_timer() -> Box<TimerStop<Result = (Second, Second)>> {10+pub fn get_cpu_timer() -> Box<dyn TimerStop<Result = (Second, Second)>> {11 Box::new(CPUTimer::start())12 }13 14 struct CPUTimer {50 unmodified lines65 system: ((end.system_usec - start.system_usec) as f64) * 1e-6,66 }67 }68 69+#[cfg(test)]70+use approx::assert_relative_eq;71+72 #[test]73 fn test_cpu_time_interval() {74 let t_a = CPUTimes {75 user_usec: 12345,20 unmodified linesmodified:src/hyperfine/timer/wallclocktimer.rs+2 added-2 removed
1 use std::process::Child;2 use std::time::Instant;3 4-use hyperfine::timer::{TimerStart, TimerStop};5-use hyperfine::units::Second;4+use crate::hyperfine::timer::{TimerStart, TimerStop};5+use crate::hyperfine::units::Second;6 7 pub struct WallClockTimer {8 start: Instant,9 }21 unmodified linesmodified:src/hyperfine/timer/windows_timer.rs+2 added-2 removed
1 #![cfg(windows)]2 3 use super::internal::CPUTimes;4-use hyperfine::timer::{TimerStart, TimerStop};5-use hyperfine::units::Second;4+use crate::hyperfine::timer::{TimerStart, TimerStop};5+use crate::hyperfine::units::Second;6 7 use winapi::um::processthreadsapi::GetProcessTimes;8 use winapi::um::winnt::HANDLE;9 73 unmodified linesmodified:src/hyperfine/app.rs+1 added-1 removed
1 use atty;2 use atty::Stream;3-use clap::{App, AppSettings, Arg, ArgMatches};3+use clap::{crate_version, App, AppSettings, Arg, ArgMatches};4 use std::ffi::OsString;5 6 pub fn get_arg_matches<T>(args: T) -> ArgMatches<'static>7 where183 unmodified linesmodified:src/hyperfine/benchmark.rs+14 added-14 removed
3 unmodified lines4 5 use colored::*;6 use statistical::{mean, standard_deviation};7 8-use hyperfine::format::{format_duration, format_duration_unit};9-use hyperfine::internal::{get_progress_bar, max, min, MIN_EXECUTION_TIME};10-use hyperfine::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD};11-use hyperfine::shell::execute_and_time;12-use hyperfine::timer::wallclocktimer::WallClockTimer;13-use hyperfine::timer::{TimerStart, TimerStop};14-use hyperfine::types::{8+use crate::hyperfine::format::{format_duration, format_duration_unit};9+use crate::hyperfine::internal::{get_progress_bar, max, min, MIN_EXECUTION_TIME};10+use crate::hyperfine::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD};11+use crate::hyperfine::shell::execute_and_time;12+use crate::hyperfine::timer::wallclocktimer::WallClockTimer;13+use crate::hyperfine::timer::{TimerStart, TimerStop};14+use crate::hyperfine::types::{15 BenchmarkResult, CmdFailureAction, Command, HyperfineOptions, OutputStyleOption,16 };17-use hyperfine::units::Second;18-use hyperfine::warnings::Warnings;17+use crate::hyperfine::units::Second;18+use crate::hyperfine::warnings::Warnings;19 20 /// Results from timing a single shell command21 #[derive(Debug, Default, Copy, Clone)]22 pub struct TimingResult {18 unmodified lines41 42 /// Run the given shell command and measure the execution time43 pub fn time_shell_command(44 shell: &str,45- command: &Command,45+ command: &Command<'_>,46 show_output: bool,47 failure_action: CmdFailureAction,48 shell_spawning_time: Option<TimingResult>,49 ) -> io::Result<(TimingResult, bool)> {95 unmodified lines145 }146 147 fn run_intermediate_command(148 shell: &str,149- command: &Option<Command>,149+ command: &Option<Command<'_>>,150 show_output: bool,151 error_output: &'static str,152 ) -> io::Result<TimingResult> {153 if let &Some(ref cmd) = command {10 unmodified lines164 165 /// Run the command specified by `--prepare`.166 fn run_preparation_command(167 shell: &str,168- command: &Option<Command>,168+ command: &Option<Command<'_>>,169 show_output: bool,170 ) -> io::Result<TimingResult> {171 let error_output = "The preparation command terminated with a non-zero exit code. \172 Append ' || true' to the command if you are sure that this can be ignored.";3 unmodified lines176 177 /// Run the command specified by `--cleanup`.178 fn run_cleanup_command(179 shell: &str,180- command: &Option<Command>,180+ command: &Option<Command<'_>>,181 show_output: bool,182 ) -> io::Result<TimingResult> {183 let error_output = "The cleanup command terminated with a non-zero exit code. \184 Append ' || true' to the command if you are sure that this can be ignored.";3 unmodified lines188 189 /// Run the benchmark for a single shell command190 pub fn run_benchmark(191 num: usize,192- cmd: &Command,192+ cmd: &Command<'_>,193 shell_spawning_time: TimingResult,194 options: &HyperfineOptions,195 ) -> io::Result<BenchmarkResult> {196 println!(208 unmodified linesmodified:src/hyperfine/error.rs+2 added-2 removed
14 unmodified lines15 }16 }17 18 impl fmt::Display for ParameterScanError {19- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {19+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {20 write!(f, "{}", self.description())21 }22 }23 13 unmodified lines37 EmptyRunsRange,38 }39 40 impl fmt::Display for OptionsError {41- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {41+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {42 write!(f, "{}", self.description())43 }44 }45 8 unmodified linesmodified:src/hyperfine/format.rs+1 added-1 removed
1-use hyperfine::units::{Second, Unit};1+use crate::hyperfine::units::{Second, Unit};2 3 /// Format the given duration as a string. The output-unit can be enforced by setting `unit` to4 /// `Some(target_unit)`. If `unit` is `None`, it will be determined automatically.5 pub fn format_duration(duration: Second, unit: Option<Unit>) -> String {61 unmodified linesmodified:src/hyperfine/internal.rs+2 added-2 removed
1 use colored::*;2 use indicatif::{ProgressBar, ProgressStyle};3 4-use hyperfine::types::{BenchmarkResult, OutputStyleOption};5-use hyperfine::units::Second;4+use crate::hyperfine::types::{BenchmarkResult, OutputStyleOption};5+use crate::hyperfine::units::Second;6 7 use std::cmp::Ordering;8 use std::iter::Iterator;9 86 unmodified linesmodified:src/hyperfine/shell.rs+1 added-1 removed
1 use std;2 use std::io;3 use std::process::{Command, ExitStatus, Stdio};4 5-use hyperfine::timer::get_cpu_timer;5+use crate::hyperfine::timer::get_cpu_timer;6 7 /// Used to indicate the result of running a command8 #[derive(Debug, Copy, Clone)]9 pub struct ExecuteResult {84 unmodified linesmodified:src/hyperfine/types.rs+3 added-2 removed
1 /// This module contains common internal types.2+use serde::*;3 use std::fmt;4 4-use hyperfine::units::{Second, Unit};5+use crate::hyperfine::units::{Second, Unit};6 7 #[cfg(not(windows))]8 pub const DEFAULT_SHELL: &str = "sh";9 40 unmodified lines50 }51 }52 53 impl<'a> fmt::Display for Command<'a> {53- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {54+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {55 write!(f, "{}", self.get_shell_command())56 }57 }58 150 unmodified linesmodified:src/hyperfine/warnings.rs+4 added-4 removed
1 use std::fmt;2 3-use hyperfine::format::format_duration;4-use hyperfine::internal::MIN_EXECUTION_TIME;5-use hyperfine::units::Second;3+use crate::hyperfine::format::format_duration;4+use crate::hyperfine::internal::MIN_EXECUTION_TIME;5+use crate::hyperfine::units::Second;6 7 /// A list of all possible warnings8 pub enum Warnings {9 FastExecutionTime,2 unmodified lines12 OutliersDetected,13 }14 15 impl fmt::Display for Warnings {16- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {16+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {17 match *self {18 Warnings::FastExecutionTime => write!(19 f,20 "Command took less than {:.0} ms to complete. Results might be inaccurate.",21 unmodified linesmodified:src/main.rs+11 added-41 removed
1-extern crate atty;2-3-#[macro_use]4-extern crate cfg_if;5-6-#[macro_use]7-extern crate clap;8-extern crate colored;9-extern crate csv;10-extern crate indicatif;11-extern crate serde;12-13-#[macro_use]14-extern crate serde_derive;15-extern crate serde_json;16-extern crate statistical;17-18-// Os-specific dependencies19-cfg_if! {20- if #[cfg(windows)] {21- extern crate winapi;22- } else {23- extern crate libc;24- }25-}26-27-#[cfg(test)]28-#[macro_use]29-extern crate approx;30-1 use std::cmp;2 use std::env;3 use std::error::Error;4 use std::io;4 unmodified lines9 use colored::*;10 11 mod hyperfine;12 43-use hyperfine::app::get_arg_matches;44-use hyperfine::benchmark::{mean_shell_spawning_time, run_benchmark};45-use hyperfine::error::{OptionsError, ParameterScanError};46-use hyperfine::export::{ExportManager, ExportType};47-use hyperfine::internal::write_benchmark_comparison;48-use hyperfine::types::{13+use crate::hyperfine::app::get_arg_matches;14+use crate::hyperfine::benchmark::{mean_shell_spawning_time, run_benchmark};15+use crate::hyperfine::error::{OptionsError, ParameterScanError};16+use crate::hyperfine::export::{ExportManager, ExportType};17+use crate::hyperfine::internal::write_benchmark_comparison;18+use crate::hyperfine::types::{19 BenchmarkResult, CmdFailureAction, Command, HyperfineOptions, OutputStyleOption,20 };51-use hyperfine::units::Unit;21+use crate::hyperfine::units::Unit;22 23 /// Print error message to stderr and terminate24 pub fn error(message: &str) -> ! {25 eprintln!("{} {}", "Error:".red(), message);26 std::process::exit(1);27 }28 29 /// Runs the benchmark for the given commands60-fn run(commands: &Vec<Command>, options: &HyperfineOptions) -> io::Result<Vec<BenchmarkResult>> {30+fn run(commands: &Vec<Command<'_>>, options: &HyperfineOptions) -> io::Result<Vec<BenchmarkResult>> {31 let shell_spawning_time =32 mean_shell_spawning_time(&options.shell, &options.output_style, options.show_output)?;33 34 let mut timing_results = vec![];52 unmodified lines87 }88 }89 90 /// Build the HyperfineOptions that correspond to the given ArgMatches121-fn build_hyperfine_options(matches: &ArgMatches) -> Result<HyperfineOptions, OptionsError> {91+fn build_hyperfine_options(matches: &ArgMatches<'_>) -> Result<HyperfineOptions, OptionsError> {92 let mut options = HyperfineOptions::default();93 let str_to_u64 = |n| u64::from_str_radix(n, 10).ok();94 95 options.warmup_count = matches87 unmodified lines183 }184 185 /// Build the ExportManager that will export the results specified186 /// in the given ArgMatches217-fn build_export_manager(matches: &ArgMatches) -> ExportManager {187+fn build_export_manager(matches: &ArgMatches<'_>) -> ExportManager {188 let mut export_manager = ExportManager::new();189 {190 let mut add_exporter = |flag, exporttype| {191 if let Some(filename) = matches.value_of(flag) {8 unmodified lines200 export_manager201 }202 203 /// Build the commands to benchmark234-fn build_commands<'a>(matches: &'a ArgMatches) -> Vec<Command<'a>> {204+fn build_commands<'a>(matches: &'a ArgMatches<'_>) -> Vec<Command<'a>> {205 let command_strings = matches.values_of("command").unwrap();206 207 let commands = if let Some(args) = matches.values_of("parameter-scan") {208 match parse_parameter_scan_args(args) {17 unmodified linesmodified:Cargo.lock+3 added-1 removed
151 unmodified lines152 "csv 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",153 "indicatif 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",154 "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",155 "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)",156- "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",156 "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",157 "statistical 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",158 "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",159 ]300 unmodified lines460 [[package]]461 name = "serde"462 version = "1.0.91"463 source = "registry+https://github.com/rust-lang/crates.io-index"464+dependencies = [465+ "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",466+]467 468 [[package]]469 name = "serde_derive"470 version = "1.0.90"244 unmodified linesmodified:Cargo.toml+2 added-2 removed
6 unmodified lines7 name = "hyperfine"8 readme = "README.md"9 repository = "https://github.com/sharkdp/hyperfine"10 version = "1.5.0"11+edition = "2018"12 13 [dependencies]14 colored = "1.7"15 indicatif = "0.11"16 statistical = "1.0"17 atty = "0.2.2"18 cfg-if = "0.1.7"19 csv = "1.0.7"19-serde = "1.0.91"20-serde_derive = "1.0.90"20+serde = { version = "1.0.91", features = ["derive"] }21 serde_json = "1.0.39"22 23 [target.'cfg(not(windows))'.dependencies]24 libc = "0.2"11 unmodified lines