Closed
Description
Feature gate: #![feature(array_repeat)]
This is a tracking issue for creating a fixed-size array by repeatedly Cloning
an item, or by repeatedly calling a possibly-fallible nullary FnMut
.
Public API
// core::array
pub fn repeat<T: Clone, const N: usize>(value: T) -> [T; N];
pub fn repeat_with<T, const N: usize>(f: impl FnMut() -> T) -> [T; N];
pub fn try_repeat_with<R: Try, const N: usize>(
f: impl FnMut() -> R,
) -> ChangeOutputType<R, [R::Output; N]>
where
R::Residual: Residual<[R::Output; N]>;
Steps / History
- Implementation: Add
resize(_with)
and(try_)repeat(_with)
for arrays #91506 - Final comment period (FCP)
- Stabilization PR
Unresolved Questions
repeat_with
andtry_repeat_with
are very similar tofrom_fn
andtry_from_fn
(Tracking issue fortry_array_from_fn
#89379), just that they take nullary instead of unary functions. Anyone considering stabilizing these should think about those, and vice versa.