Skip to content

Commit b7d7fc6

Browse files
committed
Hide specialized Random for array behind private trait
1 parent 5435be8 commit b7d7fc6

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

library/core/src/array/mod.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,16 +429,28 @@ impl<T: Clone, const N: usize> Clone for [T; N] {
429429

430430
#[unstable(feature = "random", issue = "130703")]
431431
impl<T: Random, const N: usize> Random for [T; N] {
432-
default fn random(source: &mut (impl RandomSource + ?Sized)) -> Self {
432+
fn random(source: &mut (impl RandomSource + ?Sized)) -> Self {
433+
SpecArrayRandom::random(source)
434+
}
435+
}
436+
437+
#[unstable(feature = "random", issue = "130703")]
438+
trait SpecArrayRandom: Sized {
439+
fn random<const N: usize>(source: &mut (impl RandomSource + ?Sized)) -> [Self; N];
440+
}
441+
442+
#[unstable(feature = "random", issue = "130703")]
443+
impl<T: Random> SpecArrayRandom for T {
444+
default fn random<const N: usize>(source: &mut (impl RandomSource + ?Sized)) -> [T; N] {
433445
from_fn(|_| T::random(source))
434446
}
435447
}
436448

437449
macro_rules! impl_random_for_integer_array {
438450
($t:ty) => {
439451
#[unstable(feature = "random", issue = "130703")]
440-
impl<const N: usize> Random for [$t; N] {
441-
fn random(source: &mut (impl RandomSource + ?Sized)) -> Self {
452+
impl SpecArrayRandom for $t {
453+
fn random<const N: usize>(source: &mut (impl RandomSource + ?Sized)) -> [$t; N] {
442454
let mut buf = [const { MaybeUninit::<$t>::uninit() }; N];
443455
// SAFETY: all elements in the buffer were initialized with
444456
// random bytes.

0 commit comments

Comments
 (0)