4 releases
0.2.6 | Jun 28, 2020 |
---|---|
0.2.5 | Jun 27, 2020 |
0.1.0 | Jun 24, 2020 |
#978 in Data structures
556 downloads per month
Used in 3 crates
(via annonars)
54KB
1.5K
SLoC
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 :)
Example
// 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
assert_eq!(vec.get(0), Some(true));
assert_eq!(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.get_mut(1).unwrap();
assert_eq!(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();
assert_eq!(iter.next(), Some(true));
assert_eq!(iter.next(), Some(false));
assert_eq!(iter.next(), None);