We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
array::from_fn
1 parent f1580f3 commit 80d776eCopy full SHA for 80d776e
library/core/src/array/mod.rs
@@ -430,12 +430,7 @@ impl<T: Clone, const N: usize> Clone for [T; N] {
430
#[unstable(feature = "random", issue = "130703")]
431
impl<T: Random, const N: usize> Random for [T; N] {
432
fn random(source: &mut (impl RandomSource + ?Sized)) -> Self {
433
- let mut buf = [const { MaybeUninit::uninit() }; N];
434
- for elem in &mut buf {
435
- elem.write(T::random(source));
436
- }
437
- // SAFETY: all elements of the array were initialized.
438
- unsafe { mem::transmute_copy(&buf) }
+ from_fn(|_| T::random(source))
439
}
440
441
0 commit comments