Skip to content

Commit e0a70fd

Browse files
authored
Change to use array::from_fn in Distribution<[T; N]> for StandardUniform (#1583)
1 parent 0bc3f65 commit e0a70fd

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/distr/other.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
1111
#[cfg(feature = "alloc")]
1212
use alloc::string::String;
13+
use core::array;
1314
use core::char;
1415
use core::num::Wrapping;
1516

@@ -18,7 +19,6 @@ use crate::distr::SampleString;
1819
use crate::distr::{Distribution, StandardUniform, Uniform};
1920
use crate::Rng;
2021

21-
use core::mem::{self, MaybeUninit};
2222
#[cfg(feature = "simd_support")]
2323
use core::simd::prelude::*;
2424
#[cfg(feature = "simd_support")]
@@ -238,13 +238,7 @@ where
238238
{
239239
#[inline]
240240
fn sample<R: Rng + ?Sized>(&self, _rng: &mut R) -> [T; N] {
241-
let mut buff: [MaybeUninit<T>; N] = unsafe { MaybeUninit::uninit().assume_init() };
242-
243-
for elem in &mut buff {
244-
*elem = MaybeUninit::new(_rng.random());
245-
}
246-
247-
unsafe { mem::transmute_copy::<_, _>(&buff) }
241+
array::from_fn(|_| _rng.random())
248242
}
249243
}
250244

0 commit comments

Comments
 (0)