Skip to content

refactor(core): ProcessCtx, grouped match arms, aof clarity - #193

Merged
kacy merged 1 commit into
mainfrom
refactor/foundational-crates
Feb 19, 2026
Merged

refactor(core): ProcessCtx, grouped match arms, aof clarity#193
kacy merged 1 commit into
mainfrom
refactor/foundational-crates

Conversation

@kacy

@kacy kacy commented Feb 19, 2026

Copy link
Copy Markdown
Owner

summary

final pass in the refactoring series, targeting three foundational crates.
no functional changes.

ProcessCtx in shard.rsprocess_message had 10 parameters and a
#[allow(clippy::too_many_arguments)] suppression. extracted a
ProcessCtx<'a> struct that groups all per-call mutable state. the call
site in run_shard constructs one context per recv iteration and passes
&mut ctx to both the initial dispatch and the drain loop, avoiding any
extra allocation. the clippy suppression is gone.

also added a short doc comment to dispatch clarifying it is the hot path
every command goes through.

aof.rs doc improvements — expanded the from_bytes doc comment to
explain the CRC contract and its relationship to to_bytes. added
inline byte-count comments to estimated_size for the most common
record variants so the arithmetic is self-evident without counting struct
fields mentally.

command.rs readability — extracted wrong_arity() to replace ~50
identical ProtocolError::WrongArity("CMD".into()) expressions across the
parser functions. added category comment headers (// strings, // key lifecycle, // list, etc.) to is_write() and command_name() so each
data-type group is immediately scannable.

what was tested

  • cargo build --workspace — clean
  • cargo test -p emberkv-core -p ember-protocol -p ember-persistence -p ember-cluster -p ember-server — all pass
  • cargo clippy --workspace -- -D warnings — zero warnings

shard.rs
- extract ProcessCtx<'a> struct to replace the 10-parameter signature of
  process_message, removing #[allow(clippy::too_many_arguments)]
- call site in run_shard constructs one ProcessCtx per recv iteration;
  the drain loop reuses the same ctx via &mut reborrow
- expand dispatch doc comment to clarify it is the hot path

aof.rs
- improve from_bytes doc comment to note CRC responsibility and relation
  to to_bytes format
- add inline byte-count comments to the Set, Del/LPop/Persist/Incr,
  Expire/Pexpire, and LPush/RPush arms of estimated_size

command.rs
- extract wrong_arity() helper to reduce ProtocolError::WrongArity("X".into())
  boilerplate across ~50 parse functions
- add category comment headers to is_write() and command_name() so each
  data-type group is immediately visible without reading every arm
@kacy
kacy merged commit 0b14835 into main Feb 19, 2026
4 of 7 checks passed
@kacy
kacy deleted the refactor/foundational-crates branch February 19, 2026 02:42
kacy added a commit that referenced this pull request Feb 19, 2026
shard.rs
- extract ProcessCtx<'a> struct to replace the 10-parameter signature of
  process_message, removing #[allow(clippy::too_many_arguments)]
- call site in run_shard constructs one ProcessCtx per recv iteration;
  the drain loop reuses the same ctx via &mut reborrow
- expand dispatch doc comment to clarify it is the hot path

aof.rs
- improve from_bytes doc comment to note CRC responsibility and relation
  to to_bytes format
- add inline byte-count comments to the Set, Del/LPop/Persist/Incr,
  Expire/Pexpire, and LPush/RPush arms of estimated_size

command.rs
- extract wrong_arity() helper to reduce ProtocolError::WrongArity("X".into())
  boilerplate across ~50 parse functions
- add category comment headers to is_write() and command_name() so each
  data-type group is immediately visible without reading every arm
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