Skip to content

Refactor: Implement Display trait and improve code quality#7

Open
kyluke wants to merge 2 commits intomainfrom
claude/fix-open-issue-UHQHR
Open

Refactor: Implement Display trait and improve code quality#7
kyluke wants to merge 2 commits intomainfrom
claude/fix-open-issue-UHQHR

Conversation

@kyluke
Copy link
Member

@kyluke kyluke commented Feb 26, 2026

Summary

This PR refactors the codebase to implement Rust's Display trait for better idiomatic string conversion, improves code quality through various clippy suggestions, and makes numerous small improvements to code clarity and maintainability.

Key Changes

Display Trait Implementation

  • Model enum: Replaced custom to_string() method with std::fmt::Display implementation, removing unnecessary .to_owned() calls
  • Verbosity enum: Replaced custom to_string() method with Display trait implementation
  • Role enum: Replaced custom to_string() method with Display trait implementation

Default Trait Improvements

  • Verbosity enum: Converted to use #[derive(Default)] with #[default] attribute instead of manual implementation
  • MessageType enum: Converted to use #[derive(Default)] with #[default] attribute
  • PresetConfig struct: Converted to use #[derive(Default)] instead of manual implementation
  • PreambleConfig struct: Converted to use #[derive(Default)] instead of manual implementation

Code Quality & Idiom Improvements

  • Replaced map_err(|e| function(e)) with map_err(function) for cleaner error handling
  • Replaced starts_with() checks with strip_prefix() for more idiomatic string handling
  • Replaced filter_map() with map() where filtering logic was unnecessary
  • Replaced .min(1.0).max(0.0) with .clamp(0.0, 1.0) for range clamping
  • Replaced map_or(false, ...) with is_ok_and() and is_some_and() for better readability
  • Replaced vec![...] with array literals [...] where appropriate
  • Simplified conditional logic by removing unnecessary nesting
  • Replaced &format!(...) with format!(...) where reference wasn't needed
  • Replaced format_args!(...).to_string() with direct string formatting

Documentation & Comments

  • Converted doc comments (///) to regular comments (//) for module-level documentation where appropriate
  • Improved comment formatting consistency

Minor Fixes

  • Removed unused imports (e.g., use chrono;)
  • Added #[allow(clippy::too_many_arguments)] attributes where needed
  • Added #[allow(clippy::module_inception)] attribute
  • Replaced "\n" with '\n' for single character strings
  • Simplified pattern matching with if let and or_else() chains
  • Improved variable naming and clarity in several functions

Implementation Details

  • All changes maintain backward compatibility and functionality
  • The refactoring prioritizes idiomatic Rust patterns and compiler suggestions
  • String conversion now leverages Rust's standard Display trait for consistency
  • Error handling is more concise while maintaining clarity

https://claude.ai/code/session_01J96NRV6o9dKTmr7igJmcaG

…ngs=deny

The project has `[lints.rust] warnings = "deny"` in Cargo.toml which turns
all compiler and clippy warnings into hard errors. This causes build failures
on different Rust toolchain versions that may introduce new warnings.

Fixes include:
- Replace manual strip_prefix/strip_suffix with std methods
- Use Display trait instead of inherent to_string() methods
- Simplify filter_map/find_map where possible
- Remove unnecessary format!/to_string calls
- Fix empty lines after doc comments
- Use clamp() instead of manual min/max pattern
- Replace &Vec<T> with &[T] in function signatures
- Use if-let instead of is_some()+unwrap()
- Add #[allow] for structural issues (too_many_arguments, type_complexity)

Closes #6

https://claude.ai/code/session_01J96NRV6o9dKTmr7igJmcaG
Change module-level and section-header /// doc comments to // regular
comments where they don't document a specific item, preventing
empty-line-after-doc-comment clippy warnings. Also inline remaining
format!() calls in println!() macros.

https://claude.ai/code/session_01J96NRV6o9dKTmr7igJmcaG
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