std-method
slice::chunks_exact_mut
Visit complete nonoverlapping mutable groups. Consume the iterator using into_remainder to access the incomplete suffix; zero size panics. Expected stdout (not executed): [2, 1, 4, 3, 0] Common mistake: Forgetting that the incomplete suffix is excluded from iteration.
Formal Syntax & Structure
rust syntaxrust
slice.chunks_exact_mut(size)Working Example
Example Snippetrust
fn main() { let mut data = [1, 2, 3, 4, 5]; let mut groups = data.chunks_exact_mut(2); for group in &mut groups { group.reverse(); } groups.into_remainder().fill(0); println!("{data:?}");}