Function core::array::from_fn

source · []
pub fn from_fn<F, T, const N: usize>(cb: F) -> [T; N] where
    F: FnMut(usize) -> T, 
🔬 This is a nightly-only experimental API. (array_from_fn #89379)
Expand description

Creates an array [T; N] where each array element T is returned by the cb call.


  • cb: Callback where the passed argument is the current array index.



let array = core::array::from_fn(|i| i);
assert_eq!(array, [0, 1, 2, 3, 4]);