#traits #container #static #copy #set #storage

nightly staticbitset

A container like std::collections::BitSet but static storage + Copy trait

3 unstable releases

0.5.2 Aug 4, 2022
0.5.1 Aug 4, 2022
0.1.1 Feb 2, 2019

#73 in #copy

MIT license

14KB
318 lines

#
use staticbitset::StaticBitSet;
#[repr(usize)]
enum Hats {
    Cap,
    Top,
    Bowler,
    Beret,
    Fez,
}
use Hats::*;
use core::mem;

type HatBitSet = StaticBitSet::<{mem::variant_count::<Hats>()}>;
assert_eq!(4, mem::size_of::<HatBitSet>());

assert_eq!(8, mem::size_of::< StaticBitSet::<64> >());
assert_eq!(4, mem::size_of::< StaticBitSet::<32> >());
assert_eq!(4, mem::size_of::< StaticBitSet::<31> >());

let mut x = StaticBitSet::<64>::default();
assert!(!x.contains(Fez as usize));

x.insert(Fez as usize);
assert!(x.contains(Fez as usize));

x.clear();
assert!(!x.contains(Fez as usize));

x.set(Fez as usize, true);
assert!(x.contains(Fez as usize));

x.set(Fez as usize, false);
assert!(!x.contains(Fez as usize));
assert!(!x.contains(Bowler as usize));

for hat in x.ones().into_iter() {
   println!("Hat index: {}", hat);
}

No runtime deps