Debian Codegraph @

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

raw
1 # Shared Bit-Slice Splitting
2
3 This iterator yields 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 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`] method.
10
11 ## Original
12
13 [`slice::Split`](core::slice::Split)
14
15 ## API Differences
16
17 The predicate function receives both the index within the bit-slice, as well as
18 the bit value, in order to allow the predicate to have more than one bit of
19 information when splitting.
20
21 ## Examples
22
23 ```rust
24 use bitvec::prelude::*;
25
26 let bits = bits![0, 0, 0, 1, 1, 1, 0, 1];
27 let mut split = bits.split(|idx, _bit| idx % 3 == 2);
28
29 assert_eq!(split.next().unwrap(), bits![0; 2]);
30 assert_eq!(split.next().unwrap(), bits![1; 2]);
31 assert_eq!(split.next().unwrap(), bits![0, 1]);
32 assert!(split.next().is_none());
33 ```
34
35 [`BitSlice::split`]: crate::slice::BitSlice::split