Skip to content

Commit acc269d

Browse files
authored
Rollup merge of #100462 - zohnannor:master, r=thomcc
Clarify `array::from_fn` documentation I've seen quite a few of people on social media confused of where the length of array is coming from in the newly stabilized `array::from_fn` example. This PR tries to clarify the documentation on this.
2 parents 7fcf850 + 289ad1a commit acc269d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

library/core/src/array/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ pub use iter::IntoIter;
3232
/// # Example
3333
///
3434
/// ```rust
35+
/// // type inference is helping us here, the way `from_fn` knows how many
36+
/// // elements to produce is the length of array down there: only arrays of
37+
/// // equal lengths can be compared, so the const generic parameter `N` is
38+
/// // inferred to be 5, thus creating array of 5 elements.
3539
/// let array = core::array::from_fn(|i| i);
3640
/// assert_eq!(array, [0, 1, 2, 3, 4]);
3741
/// ```

0 commit comments

Comments
 (0)