Reduce serde and iterator forwarding boilerplate#65
Open
jskoiz wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.src/with.rsforward_singleton_deserialize!(both Deserializer impls, 48 methods) +forward_visit_scalars!(recursive Visitor's 20 scalar visits)src/ser.rsserialize_value_from_scalars!across 5 Serializer impls (10 uniform numeric methods)src/ast.rsmapping_projection_iter!for 7 Mapping iterator viewssrc/event_de/source.rsscalar_key_at/scalar_key_at_inWhat is intentionally left explicit
These are not boilerplate and stay hand-written:
with.rs: the recursivevisit_some/visit_seq/visit_map/visit_newtype_struct(real recursion) and the*AsEnumvisitors.ser.rs:bool,i128,u128keep per-serializer handling (lossless 128-bit narrowing inValueSerializer, width preservation inPreserveNumberSerializer).&mut Serializer<W>is untouched.ast.rs:IntoIter(identity, no projection).Verification
cargo test: 909 passed, 0 failed; 8 doctests passedcargo clippy --all-targets: clean--no-default-featuresdocs/PUBLIC_API.txt(scripts/check-public-api.shexits 0 with no diff) — SemVer-safe, no doc update requiredThe macros are private (no
#[macro_export]) and expand to the same items that were written by hand, so the change is purely internal.