FixedBitSet could use an upgrade

This works, but could be more elegant.

  1. FixedBitSet is actually RunTimeSizedBitSet, because it predates const generic parameters and has a Vec inside. Is there a replacement yet which just gives you some fixed number of bits at compile time and compiles down to the machine bit instructions?

  2. FixedBitSet has "Debug", but it's not too useful. It gives you, in decimal, the values in the internal Vec. So here I write one that gives you which bits are set, as [1, 3, 5]. Can that be rewritten in functional style?

1 Like

Something like this? Unfortunately arithmetic expressions in const generics are not stable yet so the ideal struct BitSet<const BITS: usize>([u8; (BITS + 7) / 8]) won't work. Also, of course, for sizes up to 64 bits you can do better by just wrapping a u64.

Edit: there is also bitvec::array::BitArray - Rust

Right. I've hit that one. I do a lot of decoding of strange binary formats, and often need that sort of thing. Looking forward to that making it to stable and libraries following along.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.