Skip to content

Commit b0098b7

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 124cc92 commit b0098b7

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
@@ -1082,11 +1082,13 @@ mod prim_str {}
10821082
/// * [`Debug`]
10831083
/// * [`Default`]
10841084
/// * [`Hash`]
1085+
/// * [`Random`]
10851086
/// * [`From<[T; N]>`][from]
10861087
///
10871088
/// [from]: convert::From
10881089
/// [`Debug`]: fmt::Debug
10891090
/// [`Hash`]: hash::Hash
1091+
/// [`Random`]: random::Random
10901092
///
10911093
/// The following traits are implemented for tuples of any length. These traits have
10921094
/// 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
@@ -2,6 +2,7 @@
22

33
use crate::cmp::Ordering::{self, *};
44
use crate::marker::{ConstParamTy_, StructuralPartialEq, UnsizedConstParamTy};
5+
use crate::random::{Random, RandomSource};
56

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

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

0 commit comments

Comments
 (0)