This crate provides the BoolVec
structure. This is basically a wrapper around a Vec<u8>
where each byte is interpreted as 8 bool
.
Quick Note: Do what you want with this code, I don't really care :)
``rust
// Create a new
BoolVec`
use boolvec::BoolVec;
let mut vec = BoolVec::new();
// You can push data onto it vec.push(true); vec.push(false);
// ... retreve it asserteq!(vec.get(0), Some(true)); asserteq!(vec.get(3), None);
// ... update it vec.set(0, false); assert_eq!(vec.get(0), Some(false));
// You can get a reference to an unaligned boolean. let mut boolean = vec.getmut(1).unwrap(); asserteq!(boolean.get(), false);
boolean.set(true); assert_eq!(vec.get(1), Some(true));
// You can also iterate over this data (mutably or not). let mut iter = vec.iter_mut();
iter.next().unwrap().set(true); iter.next().unwrap().set(false);
let mut iter = vec.iter();
asserteq!(iter.next(), Some(true)); asserteq!(iter.next(), Some(false)); assert_eq!(iter.next(), None); ```