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