| Crates.io | bit-iter |
| lib.rs | bit-iter |
| version | 1.3.1 |
| created_at | 2021-06-17 14:23:00.433213+00 |
| updated_at | 2025-03-04 23:32:44.259329+00 |
| description | Iterate forward or backwards over the positions of set bits in a word. |
| homepage | |
| repository | https://github.com/ctamblyn/bit-iter |
| max_upload_size | |
| id | 411371 |
| size | 16,625 |
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.
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.
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).