pub fn repeat<T, const N: usize>(val: T) -> [T; N]where
T: Clone,
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.
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!"]);
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/array/fn.repeat.html