mirror of
https://github.com/sharkdp/hyperfine.git
synced 2024-11-26 13:07:05 +03:00
Factor common operations into closure
This commit is contained in:
parent
a5ce659b9c
commit
3f79985473
12
src/main.rs
12
src/main.rs
@ -93,17 +93,15 @@ fn main() {
|
||||
/// Build the HyperfineOptions that correspond to the given ArgMatches
|
||||
fn build_hyperfine_options(matches: &ArgMatches<'_>) -> Result<HyperfineOptions, OptionsError> {
|
||||
let mut options = HyperfineOptions::default();
|
||||
let str_to_u64 = |n| u64::from_str_radix(n, 10).ok();
|
||||
let param_to_u64 = |param| matches.value_of(param).and_then(|n| u64::from_str_radix(n, 10).ok());
|
||||
|
||||
options.warmup_count = matches
|
||||
.value_of("warmup")
|
||||
.and_then(&str_to_u64)
|
||||
options.warmup_count = param_to_u64("warmup")
|
||||
.unwrap_or(options.warmup_count);
|
||||
|
||||
let mut min_runs = matches.value_of("min-runs").and_then(&str_to_u64);
|
||||
let mut max_runs = matches.value_of("max-runs").and_then(&str_to_u64);
|
||||
let mut min_runs = param_to_u64("min-runs");
|
||||
let mut max_runs = param_to_u64("max-runs");
|
||||
|
||||
if let Some(runs) = matches.value_of("runs").and_then(&str_to_u64) {
|
||||
if let Some(runs) = param_to_u64("runs") {
|
||||
min_runs = Some(runs);
|
||||
max_runs = Some(runs);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user