std-method
slice::split
Divide a sequence at separator elements, omitting the separators. Adjacent separators yield empty groups. Useful for parsing a simple delimited byte record. Expected stdout (not executed): [[4], [], [7]] Common mistake: Assuming empty fields are automatically discarded.
Formal Syntax & Structure
rust syntaxrust
slice.split(|item| predicate)Working Example
Example Snippetrust
fn main() { let data = [4, 0, 0, 7]; let groups: Vec<_> = data.split(|n| *n == 0).collect(); println!("{groups:?}");}