0

from_fn

 2 years ago
source link: https://doc.rust-lang.org/stable/std/array/fn.from_fn.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
pub fn from_fn<T, const N: usize, F>(cb: F) -> [T; N] where
    F: FnMut(usize) -> T, 

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

Arguments

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

Example

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

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK