Skip to content

Refactor codebase for idiomatic Rust#6

Merged
kacy merged 1 commit intomasterfrom
refactor/idiomatic-rust
Jan 29, 2026
Merged

Refactor codebase for idiomatic Rust#6
kacy merged 1 commit intomasterfrom
refactor/idiomatic-rust

Conversation

@kacy
Copy link
Owner

@kacy kacy commented Jan 29, 2026

Summary

  • Comprehensive refactoring to make the codebase more idiomatic and cleaner
  • Improved error handling with proper error types instead of panics
  • More flexible APIs using impl Into<String> patterns
  • Better documentation and test coverage

Changes

Error Handling

  • Added LogoutError type - logout now returns Result instead of panicking on missing token
  • Added DbError enum for database operations with Serialization and Request variants
  • insert() and update() now return Result to handle serialization errors

Code Quality

  • Removed unnecessary braces in imports (use reqwest::{Client}use reqwest::Client)
  • Removed redundant type annotations throughout
  • Used #[derive(Clone)] instead of manual implementation for Claims
  • Removed async from jwt_valid() (no await needed)
  • Removed debug println! statements from production code
  • Renamed Password struct to Credentials for clarity
  • Used &str in request structs with serde for efficiency
  • Added helper method add_filter() to reduce code duplication

API Improvements

  • Added set_bearer_token() method for cleaner token setting
  • Filter methods now accept impl Into<String> for flexibility
  • in_() method now accepts any IntoIterator of string-like values

Modern Rust Patterns

  • Used let-else patterns (let Some(x) = ... else { return })
  • Used format string interpolation ({e} instead of {}, e)
  • Improved doc comments with proper /// format

Tests

  • Added test_client_creation with explicit values
  • Added test_set_bearer_token
  • Added test_logout_requires_bearer_token
  • Added test_db_error_display
  • Increased test count from 15 to 19

Improvements:
- Remove unnecessary braces in imports
- Remove redundant type annotations throughout
- Use derive(Clone) instead of manual implementation for Claims
- Remove async from jwt_valid (no await needed)
- Remove debug println! statements from production code
- Fix logout() to return proper error instead of panicking
- Add LogoutError type for missing bearer token
- Add DbError enum for database operation errors
- Make insert/update return Result to handle serialization errors
- Use impl Into<String> for flexible API in filter methods
- Add set_bearer_token() method for cleaner token setting
- Rename structs for clarity (Password -> Credentials)
- Use &str in request structs with serde for efficiency
- Add helper method add_filter() to reduce code duplication
- Improve doc comments with proper /// format
- Use modern Rust patterns (let-else, format string interpolation)
- Add more comprehensive tests

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@kacy kacy merged commit b129e4b into master Jan 29, 2026
1 check passed
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.

1 participant