File: IterOnes.md

package info (click to toggle)
rust-coreutils 0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 505,620 kB
  • sloc: ansic: 103,594; asm: 28,570; sh: 8,910; python: 5,581; makefile: 472; cpp: 97; javascript: 72
file content (23 lines) | stat: -rw-r--r-- 579 bytes parent folder | download | duplicates (2)
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