How to write/read 8 true/false in a single byte on rust language
Solution 1:
You can use the bitflags
crate to use bits as bools stored in different sizes. Although it is intended for other uses, you can still leverage its functionality for it.
Solution 2:
The bitvec
crate provides facilities of the kind you're asking for:
use bitvec::prelude::*;
fn main() {
let mut data = 0u8;
let bits = data.view_bits_mut::<Lsb0>();
bits.set(3, true);
if bits[4] {
println!("xxx");
}
assert_eq!(data, 8);
}