Debian Codegraph @

debian/rust-vendor/bitvec/doc/slice/iter/IterOnes.md

raw
1 # Bit Seeking
2
3 This iterator yields indices of bits set to `1`, rather than bit-values
4 themselves. It is essentially the inverse of indexing: rather than applying a
5 `usize` to the bit-slice to get a `bool`, this applies a `bool` to get a
6 `usize`.
7
8 It is created by the [`.iter_ones()`] method on bit-slices.
9
10 ## Examples
11
12 ```rust
13 use bitvec::prelude::*;
14
15 let bits = bits![0, 1, 0, 0, 1];
16 let mut ones = bits.iter_ones();
17
18 assert_eq!(ones.next(), Some(1));
19 assert_eq!(ones.next(), Some(4));
20 assert!(ones.next().is_none());
21 ```
22
23 [`.iter_ones()`]: crate::slice::BitSlice::iter_ones