| 1 |
# Shared Bit-Slice Reverse Splitting |
| 2 |
|
| 3 |
This iterator yields `n` successive non-overlapping 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 end 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 front of the |
| 9 |
bit-slice. |
| 10 |
|
| 11 |
It is created by the [`BitSlice::rsplitn`] method. |
| 12 |
|
| 13 |
## Original |
| 14 |
|
| 15 |
[`slice::RSplitN`](core::slice::RSplitN) |
| 16 |
|
| 17 |
## API Differences |
| 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![0, 0, 0, 1, 1, 1, 0, 1]; |
| 29 |
let mut split = bits.rsplitn(2, |idx, _bit| idx % 3 == 2); |
| 30 |
|
| 31 |
assert_eq!(split.next().unwrap(), bits![0, 1]); |
| 32 |
assert_eq!(split.next().unwrap(), bits![0, 0, 0, 1, 1]); |
| 33 |
assert!(split.next().is_none()); |
| 34 |
``` |
| 35 |
|
| 36 |
[`BitSlice::rsplitn`]: crate::slice::BitSlice::rsplitn |