#bit-flags #bit-manipulation #iterator #bit #flags

no-std bit-iter

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

8 releases (stable)

1.3.1 Mar 4, 2025
1.2.0 Aug 24, 2023
1.1.1 May 18, 2022
1.1.0 Nov 12, 2021
0.1.4 Jun 23, 2021

#266 in Algorithms

Download history 1175/week @ 2025-01-13 1330/week @ 2025-01-20 1058/week @ 2025-01-27 1638/week @ 2025-02-03 1360/week @ 2025-02-10 1307/week @ 2025-02-17 1573/week @ 2025-02-24 2134/week @ 2025-03-03 1691/week @ 2025-03-10 1719/week @ 2025-03-17 1745/week @ 2025-03-24 2648/week @ 2025-03-31 1734/week @ 2025-04-07 1496/week @ 2025-04-14 1572/week @ 2025-04-21 1373/week @ 2025-04-28

6,215 downloads per month
Used in 6 crates (5 directly)

MIT license

14KB
274 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.82.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.3.x -> 1.4.0).

No runtime deps