bitit 0.1.1

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: 19.36 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: 15s 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.

Provides simple and efficient iterators for integer types.

Examples

fn main() {
    use bitit::BitIter;

    let x: u8 = 0b10101100;

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

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

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

    // Or see them all as bools:
    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:

4 8 32 128
1 2 16 64
2 3 5 7
10101100

Features

Bitit provides the following iterators with the BitIter trait:

  • Iterating ones from least to most significant with BitIter::ones
  • Iterating zeros from least to most significant with BitIter::zeros
  • Iterating the bitwise indices of all ones with BitIter::one_indices
  • Iterating the bitwise indices of all zeros with BitIter::zero_indices
  • Iterating all bits as booleans from least to most significant with BitIter::bits
  • Iterating all bits as booleans from most to least significant with BitIter::bits_rev
  • The ability to reverse all iterators (except BitIter::bits which has BitIter::bits_rev) with Iterator::rev

The BitIter trait is implemented for all signed and unsigned primitive integers i8, u8, i16, etc. as well as usize and isize.