Skip to content

Replace hand-rolled boilerplate with idiomatic Rust patterns and standard library traits #3

@meonthewire

Description

@meonthewire

Summary

Error types are implemented manually instead of using derive macros

Error types in src/server/src/error.rs and src/server/src/auth.rs have hand-written Display, Error, and From implementations. This is verbose boilerplate that the ecosystem has standardized solutions for, and the manual implementations lack proper error chaining.

Parseable types don't implement FromStr

Types like EvictionPolicy and UserRole define their ownfrom_str() -> Option<Self>methods instead of implementing the standard std::str::FromStr trait. This prevents them from working with .parse() and other standard library APIs that expect the trait.

Metrics JSON is built with format!()

Metrics::to_json() constructs JSON output using string formatting rather than a serialization library. This approach is fragile it won't handle escaping correctly and will silently produce invalid JSON if any value contains special characters.

Opcode definitions are duplicated across crates

src/server/src/opcodes.rs and src/ctl/src/opcodes.rs define identical opcode constants independently. Changes to one must be manually mirrored in the other, and since they're raw u16 constants rather than an enum, the compiler can't check for exhaustive matching.

Acceptance Criteria

  • No manual Display or Error impls for error types
  • EvictionPolicy and UserRole implement FromStr
  • JSON generation uses serde
  • Opcodes defined in one place only
  • cargo clippy --all-targets -- -D warnings passes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions