Skip to content

Enable PacketBuilder in no_std (alloc/slice) while preserving std API#135

Open
xyzzyz wants to merge 1 commit intoJulianSchmid:masterfrom
xyzzyz:amichalik/packet-builder-no-std
Open

Enable PacketBuilder in no_std (alloc/slice) while preserving std API#135
xyzzyz wants to merge 1 commit intoJulianSchmid:masterfrom
xyzzyz:amichalik/packet-builder-no-std

Conversation

@xyzzyz
Copy link
Contributor

@xyzzyz xyzzyz commented Feb 21, 2026

PacketBuilder serialization is split from std::io::Write so packet building works in no_std environments while keeping std behavior intact.

Key changes

  • Introduce an internal writer abstraction (CoreWrite) and internal WriteError<IO, Content> in src/writer.rs.
  • Add an explicit alloc feature and make std depend on alloc.
  • Make PacketBuilder available without std.
  • Keep std write(...) -> BuildWriteError API, with BuildWriteError remaining std-only.
  • Add no_std-capable write APIs:
    • write_to_vec (alloc) with BuildVecWriteError
    • write_to_slice (no alloc) with BuildSliceWriteError
  • Refactor IPv4/IPv6 extension writing through shared internal methods used by both std and no_std paths.
  • Add docsrs cfg annotations for alloc-only APIs.
  • Add focused tests for vec and slice write paths:
    • write to empty vec
    • write to pre-populated vec
    • write to slice success path
    • write to slice too-small error path

Compatibility

  • std users keep existing PacketBuilder::write behavior.
  • no_std users gain packet serialization through vec/slice writers.

PacketBuilder serialization is split from std::io::Write so packet building
works in no_std environments while keeping std behavior intact.

Key changes
- Introduce an internal writer abstraction (`CoreWrite`) and internal
  `WriteError<IO, Content>` in `src/writer.rs`.
- Add an explicit `alloc` feature and make `std` depend on `alloc`.
- Make `PacketBuilder` available without `std`.
- Keep std `write(...) -> BuildWriteError` API, with `BuildWriteError`
  remaining std-only.
- Add no_std-capable write APIs:
  - `write_to_vec` (alloc) with `BuildVecWriteError`
  - `write_to_slice` (no alloc) with `BuildSliceWriteError`
- Refactor IPv4/IPv6 extension writing through shared internal methods used by
  both std and no_std paths.
- Add docsrs cfg annotations for alloc-only APIs.
- Add focused tests for vec and slice write paths:
  - write to empty vec
  - write to pre-populated vec
  - write to slice success path
  - write to slice too-small error path

Compatibility
- std users keep existing `PacketBuilder::write` behavior.
- no_std users gain packet serialization through vec/slice writers.
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