Skip to content

refactor: apply Rust best practices across all source files#56

Draft
Copilot wants to merge 1 commit into
mainfrom
copilot/optimize-all-rust-code
Draft

refactor: apply Rust best practices across all source files#56
Copilot wants to merge 1 commit into
mainfrom
copilot/optimize-all-rust-code

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 18, 2026

Systematic Rust idiom cleanup across the entire codebase — eliminating panic-prone patterns, reducing code duplication, and improving idiomatic style.

Bug fixes (potential panics)

  • psd_to_png: Logged error then unwrap()-ed anyway — would still panic. Replaced with ? propagation and proper ok_or_else on RgbaImage::from_raw
  • selected_file.rs: .ok().unwrap() on COM query() call — silently converted to panic. Changed to let _ = ...
  • tray.rs: store(...).unwrap() in event handler — replaced with let-else + log
  • utils/mod.rs: metadata().unwrap() — replaced with .ok()?
  • selected_file.rs: GetItemAt(i).unwrap() in loop — replaced with let Ok(...) else { continue }

Duplicate plugin registration

tauri_plugin_store was registered twice in lib.rs; removed the duplicate.

is_err()/is_none() + unwrap() antipattern → let-else / match

All occurrences across selected_file.rs, preview.rs, tray.rs, and command.rs replaced with idiomatic patterns.

Repetition elimination

config.rs had 16 identical chains of .get(key).unwrap().as_array().unwrap().iter().map(|v| v.as_str().unwrap().to_string()).collect(). Extracted into a single extract_str_vec helper; file shrunk from ~170 to ~65 lines.

Minor idioms

File Before After
audio.rs title: title, .get(0) field shorthand, .first()
monitor.rs manual impl Default #[derive(Default)]
utils/mod.rs is_file() == false, match { Some => Some, None => None } !is_file(), .map()
tar.rs (×4) format!("{}", x.to_rfc3339()) x.to_rfc3339()
ffmp.rs "seg_%03d.ts".to_string() stored in variable inline &str literals
docs/lib.rs index loop for i in 0..len { push(record[i]) } .iter().map().collect()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants