Skip to content

Commit f0718f8

Browse files
committed
Auto merge of rust-lang#104935 - matthiaskrgr:rollup-nuca86l, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#104121 (Refine `instruction_set` MIR inline rules) - rust-lang#104675 (Unsupported query error now specifies if its unsupported for local or external crate) - rust-lang#104839 (improve array_from_fn documenation) - rust-lang#104880 ([llvm-wrapper] adapt for LLVM API change) - rust-lang#104899 (rustdoc: remove no-op CSS `#help dt { display: block }`) - rust-lang#104906 (Remove AscribeUserTypeCx) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents dd98d8e + 7e75987 commit f0718f8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

core/src/array/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ mod iter;
2323
#[stable(feature = "array_value_iter", since = "1.51.0")]
2424
pub use iter::IntoIter;
2525

26-
/// Creates an array `[T; N]` where each array element `T` is returned by the `cb` call.
26+
/// Creates an array of type [T; N], where each element `T` is the returned value from `cb`
27+
/// using that element's index.
2728
///
2829
/// # Arguments
2930
///
@@ -36,8 +37,18 @@ pub use iter::IntoIter;
3637
/// // elements to produce is the length of array down there: only arrays of
3738
/// // equal lengths can be compared, so the const generic parameter `N` is
3839
/// // inferred to be 5, thus creating array of 5 elements.
40+
///
3941
/// let array = core::array::from_fn(|i| i);
42+
/// // indexes are: 0 1 2 3 4
4043
/// assert_eq!(array, [0, 1, 2, 3, 4]);
44+
///
45+
/// let array2: [usize; 8] = core::array::from_fn(|i| i * 2);
46+
/// // indexes are: 0 1 2 3 4 5 6 7
47+
/// assert_eq!(array2, [0, 2, 4, 6, 8, 10, 12, 14]);
48+
///
49+
/// let bool_arr = core::array::from_fn::<_, 5, _>(|i| i % 2 == 0);
50+
/// // indexes are: 0 1 2 3 4
51+
/// assert_eq!(bool_arr, [true, false, true, false, true]);
4152
/// ```
4253
#[inline]
4354
#[stable(feature = "array_from_fn", since = "1.63.0")]

0 commit comments

Comments
 (0)