std-method

slice::repeat

Create a vector containing n copies of the sequence. Elements must implement Copy. Repeating zero times produces an empty vector. Expected stdout (not executed): [2, 5, 2, 5, 2, 5] Common mistake: Confusing repetition of the whole sequence with repetition of each individual element.

Formal Syntax & Structure

rust syntaxrust
slice.repeat(n)

Working Example

Example Snippetrust
fn main() {    let pattern = [2, 5];    println!("{:?}", pattern.repeat(3));}
Rust Reference