Crates.io | boolvec |
lib.rs | boolvec |
version | 0.2.6 |
source | src |
created_at | 2020-06-24 16:57:12.199481 |
updated_at | 2020-06-28 00:48:58.548335 |
description | A vector of boolean stored contiguously in memory. |
homepage | |
repository | https://github.com/gymore-z/boolvec |
max_upload_size | |
id | 257623 |
size | 53,116 |
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 :)
// 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);