| 1 |
# Exclusive Bit-Slice Splitting |
| 2 |
|
| 3 |
This iterator yields `n` successive non-overlapping mutable segments of a |
| 4 |
bit-slice, separated by bits that match a predicate function. Splitting advances |
| 5 |
one segment at a time, starting at the beginning of the bit-slice. |
| 6 |
|
| 7 |
The matched bit is **not** included in the yielded segment. The `n`th yielded |
| 8 |
segment does not attempt any further splits, and extends to the end of the |
| 9 |
bit-slice. |
| 10 |
|
| 11 |
It is created by the [`BitSlice::splitn_mut`] method. |
| 12 |
|
| 13 |
## Original |
| 14 |
|
| 15 |
[`slice::SplitNMut`](core::slice::SplitNMut) |
| 16 |
|
| 17 |
## API Differences |
| 18 |
|
| 19 |
This iterator marks all yielded bit-slices as `::Alias`ed. |
| 20 |
|
| 21 |
The predicate function receives both the index within the bit-slice, as well as |
| 22 |
the bit value, in order to allow the predicate to have more than one bit of |
| 23 |
information when splitting. |
| 24 |
|
| 25 |
## Examples |
| 26 |
|
| 27 |
```rust |
| 28 |
use bitvec::prelude::*; |
| 29 |
|
| 30 |
let bits = bits![mut 0, 0, 0, 1, 1, 1, 0, 1]; |
| 31 |
let mut split = bits.splitn_mut(2, |idx, _bit| idx % 3 == 2); |
| 32 |
|
| 33 |
split.next().unwrap().fill(true); |
| 34 |
split.next().unwrap().fill(false); |
| 35 |
assert!(split.next().is_none()); |
| 36 |
|
| 37 |
assert_eq!(bits, bits![1, 1, 0, 0, 0, 0, 0, 0]); |
| 38 |
``` |
| 39 |
|
| 40 |
[`BitSlice::splitn_mut`]: crate::slice::BitSlice::splitn_mut |