Skip to content

Commit 8f97955

Browse files
committed
Implement Random for tuple
Implement `Random` for tuples of arity 12 or less. Each element is expected to implement `Random`.
1 parent ae8ab87 commit 8f97955

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Diff for: library/core/src/primitive_docs.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1080,11 +1080,13 @@ mod prim_str {}
10801080
/// * [`Debug`]
10811081
/// * [`Default`]
10821082
/// * [`Hash`]
1083+
/// * [`Random`]
10831084
/// * [`From<[T; N]>`][from]
10841085
///
10851086
/// [from]: convert::From
10861087
/// [`Debug`]: fmt::Debug
10871088
/// [`Hash`]: hash::Hash
1089+
/// [`Random`]: random::Random
10881090
///
10891091
/// The following traits are implemented for tuples of any length. These traits have
10901092
/// implementations that are automatically generated by the compiler, so are not limited by

Diff for: library/core/src/tuple.rs

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use crate::cmp::Ordering::{self, *};
44
use crate::marker::{ConstParamTy_, StructuralPartialEq, UnsizedConstParamTy};
55
use crate::ops::ControlFlow::{Break, Continue};
6+
use crate::random::{Random, RandomSource};
67

78
// Recursive macro for implementing n-ary tuple functions and operations
89
//
@@ -123,6 +124,16 @@ macro_rules! tuple_impls {
123124
}
124125
}
125126

127+
maybe_tuple_doc! {
128+
$($T)+ @
129+
#[unstable(feature = "random", issue = "130703")]
130+
impl<$($T: Random),+> Random for ($($T,)+) {
131+
fn random(source: &mut (impl RandomSource + ?Sized)) -> Self {
132+
($({ let x: $T = Random::random(source); x},)+)
133+
}
134+
}
135+
}
136+
126137
maybe_tuple_doc! {
127138
$($T)+ @
128139
#[stable(feature = "array_tuple_conv", since = "1.71.0")]

0 commit comments

Comments
 (0)