std-method
slice::rsplit
Visit separator-delimited groups from right to left. Elements inside each group retain their original order. Expected stdout (not executed): [[3, 4], [1, 2]] Common mistake: Expecting every group itself to be reversed.
Formal Syntax & Structure
rust syntaxrust
slice.rsplit(|item| predicate)Working Example
Example Snippetrust
fn main() { let data = [1, 2, 0, 3, 4]; let groups: Vec<_> = data.rsplit(|n| *n == 0).collect(); println!("{groups:?}");}