bitreader - Rust
Expand description BitReader is a helper type to extract strings of bits from a slice of bytes. Here is how you read first a single bit, then three bits and finally four bits from a byte buffer: use bitreader::BitReader; let slice_of_u8 = &[0b1000_1111]; let mut reader = BitReader::new(slice_of_u8); let a_single_bit = reader.read_u8(1).unwrap(); assert_eq!(a_single_bit, 1); let more_bits = reader.read_u8(3).unwrap(); assert_eq!(more_bits, 0); let last_bits_of_byte = reader.read_u8(4).unwrap(); assert_eq!(last_bits_of_byte, 0b1111); You can naturally read bits from longer buffer of data than just a single byte.
https://docs.rs/bitreader/latest/bitreader/