Releases: wrenger/bitfield-struct-rs
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).
0.6.2
0.6.1
This minor release just fixes #35 (raw field names) and #36 (failing overflow tests).
Thanks to @osteffenrh and @marcfir for reporting them.
The first issue reported a bug when using r#
raw identifiers, as shown below. This is now supported.
#[bitfield(u8)]
#[derive(PartialEq)]
struct Raw {
r#type: u8,
}
let raw = Raw::new().with_type(0xff);
assert_eq!(raw.r#type(), 0xff);
0.6.0
This release added the auto-generation of the (from|into)_bits
conversion functions for bitfields (which can be disabled by [bitfield(u8, conversion = false)]
).
Together with the laxer type requirements for the conversion functions, this makes it simple to nest bitfields.
#[bitfield(u8)]
#[derive(PartialEq)]
struct Child {
contents: u8,
}
#[bitfield(u16)]
#[derive(PartialEq)]
struct Parent {
#[bits(8)]
child: Child,
other: u8,
}
let child = Child::new().with_contents(0xff);
let parent = Parent::new().with_child(child);
assert_eq!(child.into_bits(), 0xff);
assert_eq!(parent.into_bits(), 0xff);
Thanks to @Frostie314159 for implementing this feature and to @akauppi and @deeglaze for additional fixes.
0.5.6
This release introduces a new parameter to the #[bits]
attribute for making fields read-only or write-only.
#[bitfield(u16)]
struct MyBitfield {
#[bits(8, access = RO)]
read: u8,
#[bits(8, access = WO)]
write: u8,
}
let v = MyBitfield::new().with_write(0xea);
assert_eq!(v.0, 0xea00);
assert_eq!(v.read(), 0);
Thanks to @paul1999 for implementing this feature.