std-method
slice::rchunks
Group a sequence starting at its end, while preserving element order inside each group. The last yielded group may be shorter. Expected stdout (not executed): [4, 5] [2, 3] [1] Common mistake: Expecting the elements within each group to be reversed.
Formal Syntax & Structure
rust syntaxrust
slice.rchunks(chunk_size)Working Example
Example Snippetrust
fn main() { for group in [1, 2, 3, 4, 5].rchunks(2) { println!("{group:?}"); }}