From 73d3188dd231c3e27c2faeea08aa99053dc943ef Mon Sep 17 00:00:00 2001 From: xnuter Date: Thu, 10 Nov 2022 19:19:16 -0800 Subject: [PATCH] Rust version bump, address new clippy warnings --- .github/workflows/clippy.yml | 2 +- src/bench_run.rs | 12 ++---------- src/configuration.rs | 4 ++-- src/metrics.rs | 18 ++++++++++-------- src/prometheus_reporter.rs | 6 +++--- 5 files changed, 18 insertions(+), 24 deletions(-) diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 1d2e52f..3f9e8ba 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -20,7 +20,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: clippy - args: --features full -- -D warnings + args: --features full --tests -- -D warnings rustfmt: name: Format diff --git a/src/bench_run.rs b/src/bench_run.rs index 3448fa9..3965f71 100644 --- a/src/bench_run.rs +++ b/src/bench_run.rs @@ -135,17 +135,9 @@ impl BenchRun { /// Each async operation must be time-bound. pub async fn timed_operation(&self, f: T) -> Result<::Output, ()> { - if let Some(timeout_value) = self.timeout { - let result = timeout(timeout_value, f).await; + let Some(timeout_value) = self.timeout else { return Ok(f.await); }; - if let Ok(r) = result { - Ok(r) - } else { - Err(()) - } - } else { - Ok(f.await) - } + timeout(timeout_value, f).await.map_err(|_| ()) } } diff --git a/src/configuration.rs b/src/configuration.rs index 67ca984..1b5e712 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -327,8 +327,8 @@ impl BenchmarkConfig { } fn read_file_as_vec(filename: &str) -> Vec { - let mut f = File::open(&filename).expect("File not found"); - let metadata = fs::metadata(&filename).expect("Cannot get metadata"); + let mut f = File::open(filename).expect("File not found"); + let metadata = fs::metadata(filename).expect("Cannot get metadata"); let mut buffer = vec![0; metadata.len() as usize]; f.read_exact(&mut buffer) .map_err(|e| panic!("Error reading file {}: {}", filename, e)) diff --git a/src/metrics.rs b/src/metrics.rs index 4818cca..c3917f7 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -328,9 +328,11 @@ impl DefaultConsoleReporter { } fn sorted_operations(metrics: &BenchRunMetrics) -> Vec { - let sorted_operation_name: Vec = - metrics.by_operation.keys().map(|s| s.to_owned()).collect(); - sorted_operation_name + metrics + .by_operation + .keys() + .map(String::to_owned) + .collect::>() } fn build_report(&self, metrics: &BenchRunMetrics) -> BenchRunReport { @@ -472,7 +474,7 @@ mod tests { } let report = DefaultConsoleReporter::new(None).build_report(&metrics); - let mut items = report.combined.latency_summary.to_owned().into_iter(); + let mut items = report.combined.latency_summary.iter().cloned(); assert_eq!(Some(("Min".to_string(), 0)), items.next()); assert_eq!(Some(("p50".to_string(), 500)), items.next()); @@ -492,8 +494,8 @@ mod tests { .get("OperationA") .unwrap() .latency_summary - .to_owned() - .into_iter(); + .iter() + .cloned(); assert_eq!(Some(("Min".to_string(), 0)), items.next()); assert_eq!(Some(("p50".to_string(), 500)), items.next()); assert_eq!(Some(("p90".to_string(), 900)), items.next()); @@ -510,8 +512,8 @@ mod tests { .get("OperationB") .unwrap() .latency_summary - .to_owned() - .into_iter(); + .iter() + .cloned(); assert_eq!(Some(("Min".to_string(), 1)), items.next()); assert_eq!(Some(("p50".to_string(), 501)), items.next()); assert_eq!(Some(("p90".to_string(), 901)), items.next()); diff --git a/src/prometheus_reporter.rs b/src/prometheus_reporter.rs index 305912a..188ed45 100644 --- a/src/prometheus_reporter.rs +++ b/src/prometheus_reporter.rs @@ -374,7 +374,7 @@ mod test { (false, "500".to_string()) }; total_bytes += i; - successful_requests += if success { 1 } else { 0 }; + successful_requests += i32::from(success); total_requests += 1; metrics.report_request( @@ -484,7 +484,7 @@ mod test { (false, "500".to_string()) }; total_bytes += i; - successful_requests += if success { 1 } else { 0 }; + successful_requests += i32::from(success); total_requests += 1; metrics.report_request( @@ -592,7 +592,7 @@ mod test { .with_body("world") .create(); - let url = mockito::server_url().to_string(); + let url = mockito::server_url(); println!("Url: {}", url); let reporter = PrometheusReporter::new(