blessed-rs icon indicating copy to clipboard operation
blessed-rs copied to clipboard

Recommend a bit-field crate

Open averms opened this issue 1 year ago • 0 comments

I think a lot of people coming from C or C++ will expect some sort of support for structs with bit-fields. They're useful when writing drivers, emulators, and low-level networking code. The bitflags crate already recommended can be used to approximate bit-fields of 1-bit but doesn't work for any other case.

From a quick glance at lib.rs, here are the most popular options, most of which are proc-macros:

  • bitfield
  • deku, which uses bitvec
  • bitfield-struct
  • modular-bitfield
  • bitbybit
  • bilge
  • bitfields

The only ones I've tried are deku and bitbybit. I found deku to be pretty slow in terms of compile-time because of the dependency tree. It also generates a lot of assembly (which may mean it's slower but I haven't benched). I really liked bitbybit.

averms avatar Apr 25 '25 17:04 averms