repeat

Function repeat 

1.92.0 · Source
pub fn repeat<T: Clone, const N: usize>(val: T) -> [T; N]
Expand description

Creates an array of type [T; N] by repeatedly cloning a value.

This is the same as [val; N], but it also works for types that do not implement Copy.

The provided value will be used as an element of the resulting array and will be cloned N - 1 times to fill up the rest. If N is zero, the value will be dropped.

§Example

Creating multiple copies of a String:

use std::array;

let string = "Hello there!".to_string();
let strings = array::repeat(string);
assert_eq!(strings, ["Hello there!", "Hello there!"]);