std-method

slice::fill

Overwrite every element with the supplied value using Clone as needed. The length remains unchanged. Expected stdout (not executed): [false, false, false] Common mistake: Expecting fill to append or allocate additional positions.

Formal Syntax & Structure

rust syntaxrust
slice.fill(value)

Working Example

Example Snippetrust
fn main() {    let mut flags = [true, false, true];    flags.fill(false);    println!("{flags:?}");}
Rust Reference