std-method

slice::split_mut

Borrow separate mutable groups without borrowing separator positions. Modify each group independently while preserving the delimiters. Expected stdout (not executed): [8, 8, 0, 8] Common mistake: Expecting separator elements to be included in the mutable groups.

Formal Syntax & Structure

rust syntaxrust
slice.split_mut(|item| predicate)

Working Example

Example Snippetrust
fn main() {    let mut data = [1, 2, 0, 3];    for group in data.split_mut(|n| *n == 0) { group.fill(8); }    println!("{data:?}");}
Rust Reference