bitfield-derive
This crate provides derive to generate struct with bitfield access.
Examples
use BitFields;
// Instance a struct with bitfields.
let mut foo = default;
// Initial states.
assert_eq!;
assert_eq!;
foo.set_bar;
foo.set_baz;
assert_eq!;
assert_eq!;
// Overflowing tests.
foo.set_bar;
foo.set_baz;
assert_eq!;
assert_eq!;
foo.set_bar;
foo.set_baz;
assert_eq!;
assert_eq!;
assert_eq!;
// Compile fail if uncomment the follow line.
// foo.set_ro(false);
// Compile fail if uncomment the follow line.
// assert_eq!(foo.wr(), 0);
foo.set_wr;
assert_eq!;
foo.set_stuff;
assert_eq!;
// All bits in the container field.
assert_eq!;
foo.set_all_bits;
assert_eq!;
Visibility
The visibility of the bitfield follows the container field.
Examples:
use BitFields;
The container field Foo::_bi1
is pub
, so the Foo::bar() and Foo::set_bar()
are implements as:
The container field Foo::_bi2
is private
, so the Foo::baz() and Foo::set_baz()
are implements as:
Documentation
The last parameter of the bitfield is the description of the getter
and setter
.
The document generated by the above example is as follows:
pub pub See also: bar
pub pub See also: baz
...