Bitfield Struct
Procedural macro for bitfields that allows specifying bitfields as structs.
As this library provides a procedural macro, it has no runtime dependencies and works for no-std
.
Usage
Add this to your Cargo.toml
:
[]
= "0.3"
Example
use bitfield;
/// A test bitfield with documentation
// <- Attributes after `bitfield` are applied carried over
/// A custom enum
// implement `From<u64>` and `Into<u64>` for `CustomEnum`!
// Usage:
let mut val = new
.with_int
.with_flag
.with_tiny
.with_negative
.with_custom
.with_public;
println!;
let raw: u64 = val.into;
println!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// const members
assert_eq!;
assert_eq!;
val.set_negative;
assert_eq!;
The macro generates three accessor functions for each field.
Each accessor also inherits the documentation of its field.
The signatures for addr
are:
// generated struct
;
// generated trait implementations
fmt::Debug
This macro automatically creates a suitable fmt::Debug
implementation
similar to the ones created for normal structs by #[derive(Debug)]
.
You can disable it with the extra debug argument.
let val = new.with_data;
println!