bitfield

Attribute Macro bitfield 

Source
#[bitfield]
Expand description

Creates a bitfield for this struct.

The arguments first, have to begin with the integer type of the bitfield: For example: #[bitfield(u64)].

It can contain the following additional parameters, like the debug argument for disabling the Debug trait generation (#[bitfield(u64, debug = false)]).

Parameters of the bitfield attribute:

  • the bitfield integer type (required)
  • repr specifies the bitfield’s representation in memory
  • from to specify a conversion function from repr to the bitfield’s integer type
  • into to specify a conversion function from the bitfield’s integer type to repr
  • new to disable the new function generation
  • binread to enable the BinRead trait generation
  • binwrite to enable the BinWrite trait generation
  • binrw to enable both BinRead and BinWrite trait generation
  • clone to disable the Clone trait generation
  • debug to disable the Debug trait generation
  • defmt to enable the defmt::Format trait generation
  • default to disable the Default trait generation
  • hash to generate the Hash trait
  • order to specify the bit order (Lsb, Msb)
  • conversion to disable the generation of into_bits and from_bits

For new, clone, debug, defmt or default, you can either use booleans (#[bitfield(u8, debug = false)]) or cfg attributes (#[bitfield(u8, debug = cfg(test))]) to enable/disable them.

Parameters of the bits attribute (for fields):

  • the number of bits
  • access to specify the access mode (RW, RO, WO, None)
  • default to set a default value
  • into to specify a conversion function from the field type to the bitfield type
  • from to specify a conversion function from the bitfield type to the field type