From 9f6a047867a7772a3dbdffefa22e0957f84c4516 Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Thu, 19 Nov 2026 23:20:17 +0100 Subject: [PATCH] app: compute the download percentage with checked_div The current clippy flags the `if total > 0` guard around the division as `manual_checked_ops`, and `-D warnings` turns that into a failed build, so nothing else in the app could be checked. `checked_div` says the same thing without the lint. --- app/src/app.rs | 2 +- app/src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/app.rs b/app/src/app.rs index 3581c06..8d1906d 100644 --- a/app/src/app.rs +++ b/app/src/app.rs @@ -695,7 +695,7 @@ impl App { while let Ok(event) = rx.try_recv() { match event { export::FetchEvent::Bytes { done, total } => { - let pct = if total > 0 { done * 100 / total } else { 0 }; + let pct = (done * 100).checked_div(total).unwrap_or(0); if self.ffmpeg_pct != Some(pct) { self.ffmpeg_pct = Some(pct); if self.ffmpeg_banner_showing() { diff --git a/app/src/main.rs b/app/src/main.rs index 79d8783..ce7557b 100644 --- a/app/src/main.rs +++ b/app/src/main.rs @@ -136,7 +136,7 @@ fn fetch_ffmpeg() { let shown = std::cell::Cell::new(u64::MAX); let result = export::fetch(|event| match event { export::FetchEvent::Bytes { done, total } => { - let pct = if total > 0 { done * 100 / total } else { 0 }; + let pct = (done * 100).checked_div(total).unwrap_or(0); if pct != shown.get() { shown.set(pct); println!("ffmpeg: {pct}%");