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

# Function repeat

Source

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

🔬This is a nightly-only experimental API. (`array_repeat` #126695)
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`:

    #![feature(array_repeat)]

    use std::array;

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