Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ctamblyn/bit-iter
Rust crate to iterate forwards or backwards over the positions of set bits in a word. Useful for working with event flags, some bitboards etc.
https://github.com/ctamblyn/bit-iter
bit-algorithms bit-iterator bit-twiddling bits flags iterator no-std rust
Last synced: 17 days ago
JSON representation
Rust crate to iterate forwards or backwards over the positions of set bits in a word. Useful for working with event flags, some bitboards etc.
- Host: GitHub
- URL: https://github.com/ctamblyn/bit-iter
- Owner: ctamblyn
- License: mit
- Created: 2021-05-30T19:32:20.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-12T18:30:40.000Z (about 1 year ago)
- Last Synced: 2024-10-29T08:31:10.456Z (18 days ago)
- Topics: bit-algorithms, bit-iterator, bit-twiddling, bits, flags, iterator, no-std, rust
- Language: Rust
- Homepage:
- Size: 38.1 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bit-iter
![Test results](https://github.com/ctamblyn/bit-iter/actions/workflows/quickstart.yml/badge.svg)
[![Crates.io](https://img.shields.io/crates/v/bit-iter)](https://crates.io/crates/bit-iter)
[![Documentation](https://docs.rs/bit-iter/badge.svg)](https://docs.rs/bit-iter)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
```rust
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:
```text
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.53.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.2.x -> 1.3.0).