Skip to content

Changelog, API docs, enum type inference and Bits<N> width fixes - #120

Merged
rudib merged 5 commits into
masterfrom
docs-changelog-enum-fixes
Oct 1, 2026
Merged

rudib merged 5 commits into
masterfrom
docs-changelog-enum-fixes

Conversation

@rudib

@rudib rudib commented Sep 30, 2026

Copy link
Copy Markdown
Member

Summary

  • Add a changelog. Adds short summaries of every published release and a detailed entry for the unreleased 0.12.0. The entry covers the wire-format fixes from Fix packing of unaligned integers, narrow integer widths and exclusive byte ranges #119 (exclusive byte ranges, wide unaligned fields) and includes an upgrade checklist.
  • Document the public API. Every public item in packed_struct and packed_struct_codegen now has docs, and both crates warn on missing docs. Docs that no longer matched the code are corrected, and the README gets the same fixes. The stale docs were:
    • the LsbInteger example
    • the description of sign extension
    • the byte_types_* features
    • the attribute tables
  • Fix the inferred primitive type of enums. #[derive(PrimitiveEnum)] could pick a type too small for the discriminants. For example, -3000000000 became i32, and -1 with 200 became i8, so the derive failed to compile. It now picks the smallest integer that holds both the smallest and the largest discriminant. An enum that no integer type can hold is reported as a compile error.
  • Generate Bits<N> up to the full byte width. The build script used an exclusive range, so the widest type was one bit short. As a result, ReservedZero<Bits<256>> and the 64- and 256-byte equivalents failed to compile.
  • Document lsb0 bit numbering (Question on LSB0 endianness #92). In lsb0, bit 0 is the least significant bit of the last byte, and endian only orders the bytes inside each field. That means bit_numbering="lsb0", endian="lsb" does not describe a little-endian register, which is what Question on LSB0 endianness #92 expected. This is a documentation gap, not a soundness bug. The docs now explain the numbering and include a runnable example for little-endian registers. New tests cover that example and pin the layout of the struct from the issue.

Test plan

  • cargo test --workspace, including the new doctest and tests/issue_92.rs

🤖 Generated with Claude Code

rudib and others added 5 commits October 1, 2026 00:56
Short summaries of every published release, and a detailed entry for the
unreleased 0.12.0, including the wire-format fixes for exclusive byte ranges
and wide unaligned fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every public item in packed_struct and packed_struct_codegen now has
documentation, and both crates warn on missing docs.

Existing docs that no longer matched the code are corrected: the LsbInteger
example used a value that doesn't fit in 10 bits, sign extension was
described as one's complement, the byte_types_* features only raise the
Bits<N> limit since the const generic rewrite, and the attribute tables
misdescribed size_bits, endian and the lsb0 requirements. The README gets
the same fixes as the crate docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#[derive(PrimitiveEnum)] could pick a type too small for the discriminants.
The i64 branch for negative values was unreachable, so -3000000000 became
i32, and with mixed signs the signed type won regardless of the positive
values, so -1 and 200 became i8. Both expanded into literals that don't fit
and failed to compile.

The type is now the smallest integer that holds both the smallest and the
largest discriminant, and an enum that no type can hold is reported as a
compile error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The build script generated the bit widths with an exclusive range, so the
widest type was one bit short: 255 bits by default, and 511 or 2047 bits
with byte_types_64 or byte_types_256. A reserved field of exactly 32, 64 or
256 bytes, like ReservedZero<Bits<256>>, failed to compile. The range was
inclusive until it lost its + 1 in 49809fd.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lsb0 bit 0 is the least significant bit of the last byte, so the packed
array reads as one big-endian number, and endian only orders the bytes
inside each field. bit_numbering="lsb0" with endian="lsb" therefore does
not describe a little-endian register, which is what #92 expected.

The crate docs and the README now explain the numbering and show how to
unpack a little-endian register. The issue 92 tests cover the register
recipe and pin the layout of the struct from the report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rudib
rudib merged commit b954d76 into master Oct 1, 2026
6 checks passed
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