I have to decode a data format with bit fields of various widths. BitVec looks like it will be a big help. But you can't read from a BitSlice. I need things that work like
let x1: u8 = bitstream.read(8).into(); // read 8 bits, put in x1
let x2: u16 = bitstream.read(12).into(); // read 12 bits, put in x2
as a sequential operation. It can all be done with indices, of course, but is there some crate that
already provides sequential access to a BitSlice.
Given bitvec's slice functionality, you can use the same trick std::io::Read does for &[u8] — that is, take a mutable reference to a slice reference and shorten it.
I haven't actually used bitvec for this kind of work before (only used BitVec as a variable-size bitset) so the test case may be inelegant or wrong, but I hope it demonstrates the possibility.