Skip to content

Commit 289ad1a

Browse files
committed
Clarify array:from_fn documentation
1 parent f22819b commit 289ad1a

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

0 commit comments

Comments
 (0)