From a06e76c7a7173638dbf2d33ab0cf85b86c60b6b7 Mon Sep 17 00:00:00 2001 From: LyAhn Date: Sun, 21 Jun 2026 21:00:46 +0100 Subject: [PATCH] fix: resolve Rust Clippy CI failures Derive default implementations for captioner and tagger option enums, simplify sorting and progress multiple checks, and remove redundant iterator conversions. --- src-tauri/src/captioner.rs | 18 ++++-------------- src-tauri/src/commands.rs | 12 ++++++------ src-tauri/src/indexer.rs | 9 +++------ src-tauri/src/tagger.rs | 9 ++------- 4 files changed, 15 insertions(+), 33 deletions(-) diff --git a/src-tauri/src/captioner.rs b/src-tauri/src/captioner.rs index b97da92..13aae86 100644 --- a/src-tauri/src/captioner.rs +++ b/src-tauri/src/captioner.rs @@ -78,9 +78,10 @@ static ORT_RUNTIME_INIT: Mutex = Mutex::new(false); /// knows to drop its cached `FlorenceCaptioner` and reload with the new EP. pub static CAPTION_SESSION_DIRTY: AtomicBool = AtomicBool::new(false); -#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] #[serde(rename_all = "lowercase")] pub enum CaptionAcceleration { + #[default] Auto, Cpu, Directml, @@ -96,17 +97,12 @@ impl CaptionAcceleration { } } -impl Default for CaptionAcceleration { - fn default() -> Self { - Self::Auto - } -} - -#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] #[serde(rename_all = "lowercase")] pub enum CaptionDetail { Short, Detailed, + #[default] Paragraph, } @@ -136,12 +132,6 @@ impl CaptionDetail { } } -impl Default for CaptionDetail { - fn default() -> Self { - Self::Paragraph - } -} - #[derive(Serialize)] pub struct CaptionModelStatus { pub model_id: &'static str, diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index fe70668..06053ab 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -437,7 +437,7 @@ fn list_roots() -> Vec { }) }) .collect(); - entries.sort_by(|a, b| a.name.to_lowercase().cmp(&b.name.to_lowercase())); + entries.sort_by_key(|entry| entry.name.to_lowercase()); entries } @@ -468,7 +468,7 @@ fn list_child_directories(path: &Path) -> Result, String> { }); } - entries.sort_by(|a, b| a.name.to_lowercase().cmp(&b.name.to_lowercase())); + entries.sort_by_key(|entry| entry.name.to_lowercase()); Ok(entries) } @@ -1352,7 +1352,7 @@ pub async fn find_duplicates( } }; let done = stat_counter.fetch_add(1, Ordering::Relaxed) + 1; - if done % 100 == 0 || done == total { + if done.is_multiple_of(100) || done == total { let _ = app_hash.emit( "duplicate_scan_progress", DuplicateScanProgress { @@ -1413,7 +1413,7 @@ pub async fn find_duplicates( hash_skipped.fetch_add(1, Ordering::Relaxed); } let done = counter.fetch_add(1, Ordering::Relaxed) + 1; - if done % 100 == 0 || done == c_total { + if done.is_multiple_of(100) || done == c_total { let _ = app_hash.emit( "duplicate_scan_progress", DuplicateScanProgress { @@ -1502,7 +1502,7 @@ pub async fn find_duplicates( confirm_skipped.fetch_add(1, Ordering::Relaxed); } let done = counter.fetch_add(1, Ordering::Relaxed) + 1; - if done % 100 == 0 || done == confirming_total { + if done.is_multiple_of(100) || done == confirming_total { let _ = app_confirm.emit( "duplicate_scan_progress", DuplicateScanProgress { @@ -1555,7 +1555,7 @@ pub async fn find_duplicates( .collect(); // Largest duplicates first — wastes the most space - groups.sort_by(|a, b| b.file_size.cmp(&a.file_size)); + groups.sort_by_key(|group| std::cmp::Reverse(group.file_size)); // Persist results so they survive restart — best-effort, ignore errors. let folder_scope = match folder_id { diff --git a/src-tauri/src/indexer.rs b/src-tauri/src/indexer.rs index 244ffe2..11ee641 100644 --- a/src-tauri/src/indexer.rs +++ b/src-tauri/src/indexer.rs @@ -885,7 +885,7 @@ fn process_embedding_batch( // image_id -> early error message for jobs that cannot be embedded yet let mut pre_failed: HashMap = HashMap::new(); - for (i, (job, result)) in jobs.iter().zip(source_results.into_iter()).enumerate() { + for (i, (job, result)) in jobs.iter().zip(source_results).enumerate() { match result { Ok(path) => { embeddable_indices.push(i); @@ -907,16 +907,13 @@ fn process_embedding_batch( match embedder.embed_images(&embeddable_paths) { Ok(embeddings) => { - for (job, embedding) in embeddable_jobs.iter().zip(embeddings.into_iter()) { + for (job, embedding) in embeddable_jobs.iter().zip(embeddings) { embed_results.insert(job.image_id, Ok(embedding)); } } Err(batch_error) => { log::error!("Embedding batch fallback to per-image mode: {batch_error}"); - for (job, source_path) in embeddable_jobs - .into_iter() - .zip(embeddable_paths.into_iter()) - { + for (job, source_path) in embeddable_jobs.into_iter().zip(embeddable_paths) { embed_results.insert(job.image_id, embedder.embed_image(&source_path)); } } diff --git a/src-tauri/src/tagger.rs b/src-tauri/src/tagger.rs index a30f890..52214b6 100644 --- a/src-tauri/src/tagger.rs +++ b/src-tauri/src/tagger.rs @@ -45,9 +45,10 @@ pub static TAGGER_SESSION_DIRTY: AtomicBool = AtomicBool::new(false); // Settings types // --------------------------------------------------------------------------- -#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] #[serde(rename_all = "lowercase")] pub enum TaggerAcceleration { + #[default] Auto, Cpu, Directml, @@ -63,12 +64,6 @@ impl TaggerAcceleration { } } -impl Default for TaggerAcceleration { - fn default() -> Self { - Self::Auto - } -} - // --------------------------------------------------------------------------- // Status / probe types exposed to the frontend // ---------------------------------------------------------------------------