File: IterOnes.md

package info (click to toggle)
rust-bitvec 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,780 kB
  • sloc: makefile: 2
file content (23 lines) | stat: -rw-r--r-- 579 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Bit Seeking

This iterator yields indices of bits set to `1`, rather than bit-values
themselves. It is essentially the inverse of indexing: rather than applying a
`usize` to the bit-slice to get a `bool`, this applies a `bool` to get a
`usize`.

It is created by the [`.iter_ones()`] method on bit-slices.

## Examples

```rust
use bitvec::prelude::*;

let bits = bits![0, 1, 0, 0, 1];
let mut ones = bits.iter_ones();

assert_eq!(ones.next(), Some(1));
assert_eq!(ones.next(), Some(4));
assert!(ones.next().is_none());
```

[`.iter_ones()`]: crate::slice::BitSlice::iter_ones