From 95638d453cfd457e8d1518b14fad4cb352fa07eb Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Thu, 27 Oct 2022 06:49:46 -0700 Subject: [PATCH] progress: use `clamp()` for readability This was actually what I meant in my code-review comment but I used the wrong word ("clip") :) I wasn't going to bother changing it, but Clippy nightly just started warning about it. --- src/progress.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/progress.rs b/src/progress.rs index fb343aab2..c1609f337 100644 --- a/src/progress.rs +++ b/src/progress.rs @@ -67,7 +67,7 @@ impl Drop for Progress<'_> { fn draw_progress(progress: f32, buffer: &mut String, width: usize) { const CHARS: [char; 9] = [' ', '▏', '▎', '▍', '▌', '▋', '▊', '▉', '█']; const RESOLUTION: usize = CHARS.len() - 1; - let ticks = (width as f32 * progress.min(1.0).max(0.0) * RESOLUTION as f32).round() as usize; + let ticks = (width as f32 * progress.clamp(0.0, 1.0) * RESOLUTION as f32).round() as usize; let whole = ticks / RESOLUTION; for _ in 0..whole { buffer.push(CHARS[CHARS.len() - 1]);