repeat in std::array - Rust
Description: Creates an array of type `[T; N]` by repeatedly cloning a value.

## repeat

# Function repeat

1.91.0 · Source

    pub fn repeat<T, const N: usize>(val: T) -> [T; N]where
        T: Clone,

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!"]);