bittle
A library for working with bitsets.
The name bittle comes from bit and little. Small bitsets!
This crate defines the [Bits] and [OwnedBits] traits which allows for
generically interacting with and manipulating bit sets over types such as
u128, [u32; 4], or even slices like &[u8].
To to these implementations it is possible to use bit-oriented APIs on regular types, such as with arrays and vectors:
use Bits;
let array: = set!;
assert!;
assert!;
let mut vector: = vec!;
dbg!;
assert!;
vector.bit_set;
assert_eq!;
Usage
Add bittle as a dependency in your Cargo.toml:
[]
= "0.3.5"
Guide
Due to how broadly these traits are implemented, we also try and avoid using names which are commonly used in other APIs, instead opting for terminology such as:
is_emptybecomesis_zeros.testbecomesbit_test.setbecomesbit_set.clearbecomesbits_clear.
use mem;
use Bits;
let mut a = 0u64;
assert!;
assert!;
a.bit_set;
assert!;
a.bit_clear;
assert!;
Some other interesting operations, such as Bits::join_ones are available, allowing bitsets to act like masks over other iterators:
use Bits;
let elements = vec!;
let mut m = 0u128;
m.bit_set;
assert!;
m.bit_set;
assert!;