From 3f79985473385169c8128698410534a110ad883c Mon Sep 17 00:00:00 2001 From: philipp Date: Fri, 12 Jul 2019 21:58:40 +0200 Subject: [PATCH] Factor common operations into closure --- src/main.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index a935965..a974f95 100644 --- a/src/main.rs +++ b/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 { 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); }