NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
crates.io
crates.io, #3050 most downloaded on crates.io
Easily define bitfield types with modular building blocks.
Latest stable
0.13.1
Last release 11 months ago
06 Dec 2025
Ships unpredictably
gaps range from 8 days to 4.5 years
Most releases are documented
notes for 14 of 17 stable releases
Nothing withdrawn
no release was ever pulled
8 years old
17 releases · first in 2019
Drag across the ruler to compare, or tap a release to open it.
# Bug fixes * #[repr] attributes containing lists like align(..) are now properly handled. Thanks, @minty99!
#[repr] attributes containing lists like align(..) are now properly handled. Thanks, @minty99! (#132)The BitfieldSpecifier alias, which was deprecated in v0.12, is removed.
From<[u8; {n}]> (when conversions are guaranteed) and TryFrom<[u8; {n}]> traits are now automatically derived by #[bitfield]. This will conflict with any manual implementations of the same trait, but you wrote those implementations to do this thing anyway, right? (#120)BitfieldSpecifier alias, which was deprecated in v0.12, is removed.Specifier trait.Your coding agent can read these notes before it upgrades. Set up the MCP server →
…because it derives the Specifier trait. The deprecated alias will be removed in the next release of modular-bitfield.
InvalidBitPattern::invalid_bytes field is now private. Use the InvalidBitPattern::invalid_bytes() method to access the invalid bytes (and InvalidBitPattern::new() to create new errors).#[derive(BitfieldSpecifier)] has been renamed to #[derive(Specifier)] because it derives the Specifier trait. The deprecated alias will be removed in the next release of modular-bitfield.#[must_use]. (#79)#[bitfield]. (#87)#[derive(Specifier)]. (#82)#[bitfield] on an empty struct now emits an appropriate diagnostic instead of causing a compile-time arithmetic error. (#104)Debug, tuple-like structs are now formatted normally instead of like structs with numeric fields.Fixed a bug that all but the first #[skip(..)] attribute for a bitfield were ignored despite proper error handling. E.g. when flagging a field with #[
#[skip(..)] attribute for a bitfield were ignored despite proper error handling.
E.g. when flagging a field with #[skip(getters)] #[skip(setters)] the #[skip(setters)] was ignored.Allow non-overlapping #[skip(getters)] and #[skip(setters)] attributes. This might be useful for conditional compilation.
#[skip(getters)] and #[skip(setters)] attributes. This might be useful for conditional compilation.#[skip] skipped fields not properly bumping the bit offset#[skip] attributes would yield a confusing error.Add bits: int parameter to the #[bitfield] macro which allows to precisely control the resulting bit width of the generated bitfield struct. Use it li
bits: int parameter to the #[bitfield] macro which allows to precisely control the resulting bit width
of the generated bitfield struct. Use it like: #[bitfield(bits = 5)].#[bitfield(specifier = true)] syntax with #[bitfield] #[derive(BitfieldSpecifier)].
Semantics of the new syntax is the same as the old.#[bitfield] structs with #[skip(..)] in order to skip code generation for them.
There are possibilities to skip code generation of only setters using #[skip(setters)], only getters #[skip(getters)]
or both. Having no arguments (e.g. just #[skip]) defaults to skipping both setters and getters.
A neat trick is to specify double wildcards as identifiers for skipped fields to avoid having the need to come up with
an identifier for them: For example: #[skip]: __: B10#[bitfield] fields are now properly propagated to their generated getters and setters.
Note thought that it might be confusing that an attribute applied to a struct field is actually applied to a function
through macro expansion.#[bits = N] field attributes for #[bitfield] fields.#[derive(Debug)] now produces code that the Rust 2015 edition will accept.(Thanks @jam1garner): The #[bitfield] macro now looks for #[derive(Debug)] annotations and if found will implement one that formats the struct with it
#[bitfield] macro now looks for #[derive(Debug)] annotations and if found will implement
one that formats the struct with its fields as a user would expect them. Previously having a #[derive(Debug)]
annotation on a #[bitfield] struct would simply print the contents of the generated internal byte array.#[bitfield(bytes = N)] parameter to ensure at compile time that the bitfield struct
requires N bytes of memory.#[bitfield(filled: bool)] parameter to control whether the bitfield struct ensures that either
all bits are well defined (filled = true) or if there are going to be some bits intentionally undefined (filled = false).
The default is filled = true.#[repr(uN)] for #[bitfield] structs where uN is one of u8, u16, u32, u64 or u128 with which it is
possible to control whether a bitfield allow conversions between uN and the bitfield. Also it ensures at compile time that
the bitfield requires the exact same amount of bits. This is in conflict with filled = false.#[repr(transparent)]. If a user wants their bitfield struct to remain transparent
they have to add #[repr(transparent)] manually to their struct definition.#[bitfield(specifier = bool)] got changed so that it no longer by default allows for
unfilled (filled = false) or undefined bits. Instead users now have to additionally add filled = false if they
explicitly want this behaviour.as_bytes method for #[bitfield] structs to into_bytes. It now takes self instead of &self
and returns the byte array by value instead of reference. This change was necessary for working properly with the new
#[repr(uN)] feature.#[bitfield(specifier = true)] bitfields that were not aligned to have a power-of-two bytes.Add #[bitfield(specifier = bool)] parameter with which it now is possible to have bitfield structs automatically also implement the modular_bitfield::
#[bitfield(specifier = bool)] parameter with which it now is possible to have bitfield structs automatically also
implement the modular_bitfield::Specifier trait which makes it possible to have bitfields as fields of bitfields.unsafe fn from_bytes_unchecked. Now generates a safe fn from_bytes that is basically identical.
The difference is that we no longer consider bitfields containing invalid bit patterns as invalid since generated getters
will protect their access anyways.The #[derive(BitfieldSpecifier)] now allows an amount of variants that is not a power of two via the new attribute #[bits = N] where N is the bit widt
#[derive(BitfieldSpecifier)] now allows an amount of variants that is not a power of two via
the new attribute #[bits = N] where N is the bit width of the deriving enum. (Thanks @lkolbly)Specifier implementations for u8, u16, u32, u64 and u128.#[bitfield] macro now additionally generates getters for expected failures just as it already
does for the various setters. For a field a the new fail-safe getter is called a_or_err and returns
a Result.dead_code warnings originating from generated #[bitfield] getters and setters.modular_bitfield crate and its generated code.Tons of macro generated code hygiene improvements for both #[bitfield] and #[derive(BitfieldSpecifier)].
#[bitfield] and #[derive(BitfieldSpecifier)].#[bitfield] now produces with_{} and with_{}_checked methods that take self and return Self. (Thanks @lkolbly)
#[bitfield] generated getters now are the same identifiers as their fields. (Thanks @Qyriad)
a it generated fn get_a(..) but now it generates fn a(..) instead.#[bitfield] now properly inherits visibility modifiers for all fields onto their generated getters and setters. (Thanks @WorldSEnder)TryFrom implementation from #[bitfield] generated structs since it never was really safe.
#[bitfield] generated new constructor is now a const fn.#[bitfield] generated to_bytes to as_bytes.
&[u8; N] instead of a slice.#[bitfield] macro now generates an unsafe fn from_bytes_unchecked that allows constructing from raw bytes.
unsafe replacement for the removed TryFrom implementation.criterion crate.enum variant names sometimes could clash with Rust keywords. (Thanks @Qyriad)Nothing published for this version
Add to_bytes byte conversion method to bitfield structs
to_bytes byte conversion method to bitfield structsTryFrom<&[u8]> byte conversion implementation to bitfield structsGenerate checked setters for bitfields: set_a_checked(new_val: T) -> Result<()>
set_a_checked(new_val: T) -> Result<()>B65, B66,..,B128Fixed bug with getters for 8-bit specifiers such as B8
B8no_std#[bitfield] support for tuple structsAdd assertions to setters of #[bitfield] structs to validate inputs
#[bitfield] structs to validate inputsNothing published for this version
Nothing published for this version
One column per quarter.