Skip to content

Remove the code duplication flagged by cargo-echoes - #89

Merged
LucaCappelletti94 merged 11 commits into
mainfrom
echoes-dedup
Oct 24, 2026
Merged

LucaCappelletti94 merged 11 commits into
mainfrom
echoes-dedup

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Collaborator

cargo-echoes found function bodies written once for changesets and again for patchsets, or once per wire source. Each pair now calls one shared helper, covering the binary parse loop, the JSON number decoders, the per-source digest bodies, the SQL WHERE and SET cell builders, the primary key WHERE parsing in the SQL parser, the update consolidation steps, the hex digit decoder and the column set loop in the wire builders.

The digestion tests share their row assertions through tests/common, and the benches, compile-bench and payload-size-bench plots share their setup blocks. Two tests that were exact copies of other tests are gone.

The diesel e2e scenarios now live once in the diesel_e2e lib, generic over the diesel connection with an async twin. Each backend file keeps its DDL and container boot. Every backend now runs the union of the assertions the per-backend copies used to make.

Maxwell and wal2json decoded integers, integers that overflow to text and floats with three identical bodies each. They now call decode_json_int, decode_json_int64_or_text and decode_json_real in json_decoders, beside the decoders the two sources already shared. ChangesetOp::of_stored and PatchsetOp::of_stored build the view of one stored operation, which the four iter methods of DiffSetBuilder and DiffSet spelled out, and add_insert holds the insert both formats perform.
The changeset and patchset Digestable impls of wal2json v1 and v2, Maxwell and pg_walstream repeated one match each and differed only in their UPDATE and DELETE builders. Each source now has one digest function that takes those two builders, and the impls pass theirs.
The four DELETE and UPDATE formatters each wrote the column = value loop with its separator and its unnamed-column fallback. push_cells writes it once, pk_cells and set_cells select the key cells and the changed cells.
parse_as walks the tables of either format with the format's operation parser, parse_row reads a full row image, and parse_insert handles the INSERT body both formats store alike.
@LucaCappelletti94 LucaCappelletti94 added the rust Pull requests that update rust code label Oct 24, 2026
@codecov

codecov Bot commented Oct 24, 2026

Copy link
Copy Markdown

@LucaCappelletti94
LucaCappelletti94 merged commit 49b0daf into main Oct 24, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant