Releases: wrenger/bitfield-struct-rs
0.10.1
0.9.5
0.9.4
0.10.0
This release includes an option to disable automatic Copy
and Clone
implementation. This might be useful when you want to implement your own Clone
.
/// We have a custom clone implementation -> opt out
#[bitfield(u64, clone = false)]
struct Full {
data: u64,
}
impl Clone for Full {
fn clone(&self) -> Self {
Self::new().with_data(self.data())
}
}
impl Copy for Full {}
Thanks to @kevinhartman for implementing this :)
From this release on, the set_<field>
and set_<field>_checked
setters are const
. This is possible due to Rust 1.83.0 stabilizing const mut refs. Consequently, the minimum supported Rust version was bumped to 1.83.0. This also opens the door to a more generic bitfield representation (#7).
0.9.3
0.9.2
0.9.1
0.9.0
This release adds new checked
setters, which check for integer overflows and return an error instead of panicing (like the normal setters) #49.
#[bitfield(u32)]
struct MyBitfield {
#[bits(3)]
number: i32,
#[bits(29)]
__: (),
}
assert!(MyBitfield::new().with_number_checked(4).is_err());
Also, the automatic generation of the new
function can now also be disable, similar to debug
or default
#50.
Lastly, the crate now specifies a minimal supported rust version #44.
Thanks to @EngJay, @ultimaweapon, and @DavidAntliff for reporting these issues.
0.8.0
This release adds support for auto-generating the defmt::Format
trait (#42):
#[bitfield(u64, defmt = true)]
struct DefmtExample {
data: u64
}
defmt::println!("{}", DefmtExample::new());
Thanks to @agrif for implementing this.
Also, the auto-trait implementations (Default
, Debug
, defmt::Format
) now support cfg(...)
attributes:
#[bitfield(u64, debug = cfg(test), default = cfg(feature = "foo"))]
struct CustomDebug {
data: u64
}
These cfg
attributes are added to the trait implementations, only enabling them if the conditions are met.
0.7.0
This release adds a new way to specify the memory layout of the bitfield via the repr
attribute. This makes it possible to specify the endianness for the whole bitfield as shown below.
use endian_num::be16;
#[bitfield(u16, repr = be16, from = be16::from_ne, into = be16::to_ne)]
struct MyBeBitfield {
#[bits(4)]
first_nibble: u8,
#[bits(12)]
other: u16,
}
let my_be_bitfield = MyBeBitfield::new()
.with_first_nibble(0x1)
.with_other(0x234);
assert_eq!(my_be_bitfield.into_bits().to_be_bytes(), [0x23, 0x41]);
Here, the Bitfield is represented as an be16
integer in memory. All the conversion is done automatically by calling from
and into
.
Thanks to @mkroening for implementing and documenting this feature (#39, #41).