fix: resolve Rust Clippy CI failures
github/actions/ci GitHub Actions CI finished: success

Derive default implementations for captioner and tagger option enums, simplify sorting and progress multiple checks, and remove redundant iterator conversions.
This commit is contained in:
2026-06-21 21:00:46 +01:00
parent 1e008244ae
commit a06e76c7a7
4 changed files with 15 additions and 33 deletions
+4 -14
View File
@@ -78,9 +78,10 @@ static ORT_RUNTIME_INIT: Mutex<bool> = Mutex::new(false);
/// knows to drop its cached `FlorenceCaptioner` and reload with the new EP. /// knows to drop its cached `FlorenceCaptioner` and reload with the new EP.
pub static CAPTION_SESSION_DIRTY: AtomicBool = AtomicBool::new(false); 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")] #[serde(rename_all = "lowercase")]
pub enum CaptionAcceleration { pub enum CaptionAcceleration {
#[default]
Auto, Auto,
Cpu, Cpu,
Directml, Directml,
@@ -96,17 +97,12 @@ impl CaptionAcceleration {
} }
} }
impl Default for CaptionAcceleration { #[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
fn default() -> Self {
Self::Auto
}
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "lowercase")] #[serde(rename_all = "lowercase")]
pub enum CaptionDetail { pub enum CaptionDetail {
Short, Short,
Detailed, Detailed,
#[default]
Paragraph, Paragraph,
} }
@@ -136,12 +132,6 @@ impl CaptionDetail {
} }
} }
impl Default for CaptionDetail {
fn default() -> Self {
Self::Paragraph
}
}
#[derive(Serialize)] #[derive(Serialize)]
pub struct CaptionModelStatus { pub struct CaptionModelStatus {
pub model_id: &'static str, pub model_id: &'static str,
+6 -6
View File
@@ -437,7 +437,7 @@ fn list_roots() -> Vec<DirEntry> {
}) })
}) })
.collect(); .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 entries
} }
@@ -468,7 +468,7 @@ fn list_child_directories(path: &Path) -> Result<Vec<DirEntry>, 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) Ok(entries)
} }
@@ -1352,7 +1352,7 @@ pub async fn find_duplicates(
} }
}; };
let done = stat_counter.fetch_add(1, Ordering::Relaxed) + 1; 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( let _ = app_hash.emit(
"duplicate_scan_progress", "duplicate_scan_progress",
DuplicateScanProgress { DuplicateScanProgress {
@@ -1413,7 +1413,7 @@ pub async fn find_duplicates(
hash_skipped.fetch_add(1, Ordering::Relaxed); hash_skipped.fetch_add(1, Ordering::Relaxed);
} }
let done = counter.fetch_add(1, Ordering::Relaxed) + 1; 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( let _ = app_hash.emit(
"duplicate_scan_progress", "duplicate_scan_progress",
DuplicateScanProgress { DuplicateScanProgress {
@@ -1502,7 +1502,7 @@ pub async fn find_duplicates(
confirm_skipped.fetch_add(1, Ordering::Relaxed); confirm_skipped.fetch_add(1, Ordering::Relaxed);
} }
let done = counter.fetch_add(1, Ordering::Relaxed) + 1; 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( let _ = app_confirm.emit(
"duplicate_scan_progress", "duplicate_scan_progress",
DuplicateScanProgress { DuplicateScanProgress {
@@ -1555,7 +1555,7 @@ pub async fn find_duplicates(
.collect(); .collect();
// Largest duplicates first — wastes the most space // 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. // Persist results so they survive restart — best-effort, ignore errors.
let folder_scope = match folder_id { let folder_scope = match folder_id {
+3 -6
View File
@@ -885,7 +885,7 @@ fn process_embedding_batch(
// image_id -> early error message for jobs that cannot be embedded yet // image_id -> early error message for jobs that cannot be embedded yet
let mut pre_failed: HashMap<i64, String> = HashMap::new(); let mut pre_failed: HashMap<i64, String> = 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 { match result {
Ok(path) => { Ok(path) => {
embeddable_indices.push(i); embeddable_indices.push(i);
@@ -907,16 +907,13 @@ fn process_embedding_batch(
match embedder.embed_images(&embeddable_paths) { match embedder.embed_images(&embeddable_paths) {
Ok(embeddings) => { 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)); embed_results.insert(job.image_id, Ok(embedding));
} }
} }
Err(batch_error) => { Err(batch_error) => {
log::error!("Embedding batch fallback to per-image mode: {batch_error}"); log::error!("Embedding batch fallback to per-image mode: {batch_error}");
for (job, source_path) in embeddable_jobs for (job, source_path) in embeddable_jobs.into_iter().zip(embeddable_paths) {
.into_iter()
.zip(embeddable_paths.into_iter())
{
embed_results.insert(job.image_id, embedder.embed_image(&source_path)); embed_results.insert(job.image_id, embedder.embed_image(&source_path));
} }
} }
+2 -7
View File
@@ -45,9 +45,10 @@ pub static TAGGER_SESSION_DIRTY: AtomicBool = AtomicBool::new(false);
// Settings types // Settings types
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)] #[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "lowercase")] #[serde(rename_all = "lowercase")]
pub enum TaggerAcceleration { pub enum TaggerAcceleration {
#[default]
Auto, Auto,
Cpu, Cpu,
Directml, Directml,
@@ -63,12 +64,6 @@ impl TaggerAcceleration {
} }
} }
impl Default for TaggerAcceleration {
fn default() -> Self {
Self::Auto
}
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Status / probe types exposed to the frontend // Status / probe types exposed to the frontend
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------