Skip to content

Select allocation-free serialization with the heapless feature - #76

Open
omrzk wants to merge 1 commit into
krisprice:masterfrom
omrzk:fix/heapless-serialization-73
Open

omrzk wants to merge 1 commit into
krisprice:masterfrom
omrzk:fix/heapless-serialization-73

Conversation

@omrzk

@omrzk omrzk commented Oct 29, 2026

Copy link
Copy Markdown

The heapless feature promises allocation-free formatting during serialization, but the serializers only select their existing stack-buffer path when the legacy ser_as_str feature is enabled. With heapless alone they call Serializer::collect_str, whose default implementation allocates a String.

Select the existing buffer path for either feature. This covers Ipv4Net, Ipv6Net and their IpNet wrapper while preserving binary serialization and the legacy feature. Fixes #73.

The regression measures allocations while a nonallocating serde_test serializer checks the exact emitted strings, including maximum-width addresses. On the original source, heapless alone records allocations and fails; the legacy serde,ser_as_str control passes with zero allocations.

With the fix, cargo test --features heapless, cargo test --features serde,ser_as_str, cargo test --all-features, and cargo test --no-default-features --features heapless each pass 37 unit tests, the allocation regression and 56 doctests. cargo clippy --all-features --all-targets, focused test formatting and git diff --check pass. Clippy reports existing source warnings, also present on a clean-master control. These checks establish allocation-free formatting with the test serializer; other serializers may allocate themselves.

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.

The heapless feature does not select allocation-free serialization

1 participant