Skip to content

Commit 07e8b28

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 53d4476 commit 07e8b28

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

library/core/src/primitive_docs.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1078,11 +1078,13 @@ mod prim_str {}
10781078
/// * [`Debug`]
10791079
/// * [`Default`]
10801080
/// * [`Hash`]
1081+
/// * [`Random`]
10811082
/// * [`From<[T; N]>`][from]
10821083
///
10831084
/// [from]: convert::From
10841085
/// [`Debug`]: fmt::Debug
10851086
/// [`Hash`]: hash::Hash
1087+
/// [`Random`]: random::Random
10861088
///
10871089
/// The following traits are implemented for tuples of any length. These traits have
10881090
/// implementations that are automatically generated by the compiler, so are not limited by

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::{self, Break, Continue};
6+
use crate::random::{Random, RandomSource};
67

78
// Recursive macro for implementing n-ary tuple functions and operations
89
//
@@ -139,6 +140,16 @@ macro_rules! tuple_impls {
139140
}
140141
}
141142

143+
maybe_tuple_doc! {
144+
$($T)+ @
145+
#[unstable(feature = "random", issue = "130703")]
146+
impl<$($T: Random),+> Random for ($($T,)+) {
147+
fn random(source: &mut (impl RandomSource + ?Sized)) -> Self {
148+
($({ let x: $T = Random::random(source); x},)+)
149+
}
150+
}
151+
}
152+
142153
maybe_tuple_doc! {
143154
$($T)+ @
144155
#[stable(feature = "array_tuple_conv", since = "1.71.0")]

0 commit comments

Comments
 (0)