bitit 0.1.0

A library for bitwise iteration over Rust integers.
Documentation
  • Coverage
  • 100%
    8 out of 8 items documented7 out of 7 items with examples
  • Size
  • Source code size: 17.72 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.52 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • jsode64

Bitit

A library for bitwise iteration over Rust integers.

Examples

fn main() {
    use bitit::BitIter;

    let x: u8 = 0b10101100;

    // Get ones as singular bits:
    print!("1s:\t");
    for b in x.ones() {
        print!("{b} ");
    }
    println!();

    // Or zeros:
    print!("0s:\t");
    for b in x.zeros() {
        print!("{b} ");
    }
    println!();

    // Or as indices:
    print!("1s at:\t");
    for i in x.one_indices() {
        print!("{i} ");
    }
    println!();

    // Or see them all as bools:
    print!("Bits:\t");
    for b in x.bits_rev() {
        // Using `bits_rev` so the bits are printed in the same order as defined.
        print!("{}", b as u8);
    }
    println!();
}

Output:

1s:     4 8 32 128
0s:     1 2 16 64
1s at:  2 3 5 7
Bits:   10101100