std-method
slice::split_inclusive
Keep a matching separator at the end of its group. A trailing incomplete group is also returned, which is useful for retaining record terminators. Expected stdout (not executed): [[1, 9], [2, 3, 9], [4]] Common mistake: Expecting every returned group to end with a separator.
Formal Syntax & Structure
rust syntaxrust
slice.split_inclusive(|item| predicate)Working Example
Example Snippetrust
fn main() { let bytes = [1, 9, 2, 3, 9, 4]; let records: Vec<_> = bytes.split_inclusive(|n| *n == 9).collect(); println!("{records:?}");}