Releases: wrenger/bitfield-struct-rs
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).
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.