Skip to content

Reduce serde and iterator forwarding boilerplate#65

Open
jskoiz wants to merge 1 commit into
mainfrom
claude/funny-knuth-58879a
Open

Reduce serde and iterator forwarding boilerplate#65
jskoiz wants to merge 1 commit into
mainfrom
claude/funny-knuth-58879a

Conversation

@jskoiz

@jskoiz jskoiz commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Summary

Collapses hand-copied forwarding methods into three small private macro_rules!, replacing ~115 near-identical method bodies. Net −638 src LOC (31,070 → 30,432) with no behavior change.

File Change LOC
src/with.rs forward_singleton_deserialize! (both Deserializer impls, 48 methods) + forward_visit_scalars! (recursive Visitor's 20 scalar visits) −602
src/ser.rs serialize_value_from_scalars! across 5 Serializer impls (10 uniform numeric methods) −252 / +114
src/ast.rs mapping_projection_iter! for 7 Mapping iterator views −222 / +94
src/event_de/source.rs remove unused scalar_key_at / scalar_key_at_in −18

What is intentionally left explicit

These are not boilerplate and stay hand-written:

  • with.rs: the recursive visit_some / visit_seq / visit_map / visit_newtype_struct (real recursion) and the *AsEnum visitors.
  • ser.rs: bool, i128, u128 keep per-serializer handling (lossless 128-bit narrowing in ValueSerializer, width preservation in PreserveNumberSerializer). &mut Serializer<W> is untouched.
  • ast.rs: IntoIter (identity, no projection).

Verification

  • cargo test: 909 passed, 0 failed; 8 doctests passed
  • cargo clippy --all-targets: clean
  • builds clean with and without --no-default-features
  • public API byte-identical to docs/PUBLIC_API.txt (scripts/check-public-api.sh exits 0 with no diff) — SemVer-safe, no doc update required

The macros are private (no #[macro_export]) and expand to the same items that were written by hand, so the change is purely internal.

Collapse hand-copied forwarding methods into three small declarative
macros, replacing roughly 115 near-identical method bodies:

- with.rs: forward_singleton_deserialize! for the SingletonMap and
  SingletonMapRecursive Deserializer impls, and forward_visit_scalars!
  for the recursive Visitor's scalar visits. The recursive
  visit_some/seq/map/newtype methods stay explicit.
- ser.rs: serialize_value_from_scalars! for the uniform fixed-width
  integer and float serialize methods across five Serializer impls.
  bool, i128, and u128 keep their per-serializer handling.
- ast.rs: mapping_projection_iter! for the Mapping key/value iterator
  views. IntoIter stays explicit.

Also remove two unused private helpers in event_de.

No behavior change; the public API is unchanged.
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