#bits #flags #iterator #bit-twiddling

no-std bit-iter

Iterate forward or backwards over the positions of set bits in a word

5 releases (3 stable)

1.1.1 May 18, 2022
1.1.0 Nov 12, 2021
0.1.6 Sep 29, 2021
0.1.5 Jul 16, 2021
0.1.4 Jun 23, 2021

#160 in Algorithms

Download history 2653/week @ 2022-10-08 1944/week @ 2022-10-15 1495/week @ 2022-10-22 1278/week @ 2022-10-29 1445/week @ 2022-11-05 1109/week @ 2022-11-12 798/week @ 2022-11-19 844/week @ 2022-11-26 829/week @ 2022-12-03 1004/week @ 2022-12-10 704/week @ 2022-12-17 406/week @ 2022-12-24 582/week @ 2022-12-31 433/week @ 2023-01-07 333/week @ 2023-01-14 211/week @ 2023-01-21

1,618 downloads per month
Used in 2 crates

MIT license

12KB
240 lines

bit-iter

Test results Crates.io Documentation

Iterate forwards or backwards over the positions of bits set in a word.

A BitIter may be constructed from any integral value, and returns the positions of the 1 bits in ascending order.

BitIter implements DoubleEndedIterator, so you can iterate over the positions of the set bits in descending order too.

Example

fn main() {
    use bit_iter::*;

    let x : u32 = 0x10001;

    for b in BitIter::from(x) {
        println!("Bit {} is set.", b);
    }

    println!("In reverse order:");

    for b in BitIter::from(x).rev() {
        println!("Bit {} is set.", b);
    }
}

Output:

Bit 0 is set.
Bit 16 is set.
In reverse order:
Bit 16 is set.
Bit 0 is set.

Minimum supported Rust version (MSRV) policy

bit-iter's current minimum supported Rust version (MSRV) is 1.33.0.

bit-iter is guaranteed to compile with that version. It might also compile with older versions, but that could change in a future patch release.

If the MSRV of bit-iter changes, that will be done in a minor version release (e.g. 1.1.x -> 1.2.0).

No runtime deps