32
32
#[ doc( hidden) ]
33
33
pub use ambient_authority:: ambient_authority_known_at_compile_time;
34
34
pub use ambient_authority:: { ambient_authority, AmbientAuthority } ;
35
- pub use rand:: { distributions, seq, CryptoRng , Error , Fill , Rng , RngCore , SeedableRng } ;
35
+ pub use rand:: {
36
+ distr, rand_core, seq, CryptoRng , Fill , Rng , RngCore , SeedableRng , TryCryptoRng , TryRngCore ,
37
+ } ;
36
38
37
39
/// Convenience re-export of common members.
38
40
///
39
41
/// This corresponds to [`rand::prelude`].
40
42
pub mod prelude {
41
- pub use crate :: distributions :: Distribution ;
43
+ pub use crate :: distr :: Distribution ;
42
44
#[ cfg( feature = "small_rng" ) ]
43
45
pub use crate :: rngs:: SmallRng ;
44
46
pub use crate :: rngs:: { CapRng , StdRng } ;
@@ -52,7 +54,7 @@ pub mod prelude {
52
54
pub mod rngs {
53
55
use super :: AmbientAuthority ;
54
56
55
- pub use rand:: rngs:: { adapter , mock , StdRng } ;
57
+ pub use rand:: rngs:: StdRng ;
56
58
57
59
#[ cfg( feature = "small_rng" ) ]
58
60
pub use rand:: rngs:: SmallRng ;
@@ -80,29 +82,26 @@ pub mod rngs {
80
82
}
81
83
}
82
84
83
- impl crate :: RngCore for OsRng {
84
- #[ inline]
85
- fn next_u32 ( & mut self ) -> u32 {
86
- rand:: rngs:: OsRng . next_u32 ( )
87
- }
85
+ impl crate :: TryRngCore for OsRng {
86
+ type Error = crate :: rand_core:: OsError ;
88
87
89
88
#[ inline]
90
- fn next_u64 ( & mut self ) -> u64 {
91
- rand:: rngs:: OsRng . next_u64 ( )
89
+ fn try_next_u32 ( & mut self ) -> Result < u32 , Self :: Error > {
90
+ rand:: rngs:: OsRng :: default ( ) . try_next_u32 ( )
92
91
}
93
92
94
93
#[ inline]
95
- fn fill_bytes ( & mut self , bytes : & mut [ u8 ] ) {
96
- rand:: rngs:: OsRng . fill_bytes ( bytes )
94
+ fn try_next_u64 ( & mut self ) -> Result < u64 , Self :: Error > {
95
+ rand:: rngs:: OsRng :: default ( ) . try_next_u64 ( )
97
96
}
98
97
99
98
#[ inline]
100
- fn try_fill_bytes ( & mut self , bytes : & mut [ u8 ] ) -> Result < ( ) , crate :: Error > {
101
- rand:: rngs:: OsRng . try_fill_bytes ( bytes)
99
+ fn try_fill_bytes ( & mut self , bytes : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > {
100
+ rand:: rngs:: OsRng :: default ( ) . try_fill_bytes ( bytes)
102
101
}
103
102
}
104
103
105
- impl crate :: CryptoRng for OsRng { }
104
+ impl crate :: TryCryptoRng for OsRng { }
106
105
107
106
/// The type returned by `thread_rng`, essentially just a reference to a
108
107
/// PRNG in memory.
@@ -142,11 +141,6 @@ pub mod rngs {
142
141
fn fill_bytes ( & mut self , bytes : & mut [ u8 ] ) {
143
142
self . inner . fill_bytes ( bytes)
144
143
}
145
-
146
- #[ inline]
147
- fn try_fill_bytes ( & mut self , bytes : & mut [ u8 ] ) -> Result < ( ) , crate :: Error > {
148
- self . inner . try_fill_bytes ( bytes)
149
- }
150
144
}
151
145
152
146
impl crate :: CryptoRng for CapRng { }
@@ -164,23 +158,21 @@ pub mod rngs {
164
158
#[ inline]
165
159
pub fn thread_rng ( ambient_authority : AmbientAuthority ) -> rngs:: CapRng {
166
160
let _ = ambient_authority;
167
- rngs:: CapRng {
168
- inner : rand:: thread_rng ( ) ,
169
- }
161
+ rngs:: CapRng { inner : rand:: rng ( ) }
170
162
}
171
163
172
164
/// Retrieve the standard random number generator, seeded by the system.
173
165
///
174
- /// This corresponds to [`rand::rngs::StdRng::from_entropy `].
166
+ /// This corresponds to [`rand::rngs::StdRng::from_os_rng `].
175
167
///
176
168
/// # Ambient Authority
177
169
///
178
170
/// This function makes use of ambient authority to access the platform entropy
179
171
/// source.
180
172
#[ inline]
181
- pub fn std_rng_from_entropy ( ambient_authority : AmbientAuthority ) -> rngs:: StdRng {
173
+ pub fn std_rng_from_os_rng ( ambient_authority : AmbientAuthority ) -> rngs:: StdRng {
182
174
let _ = ambient_authority;
183
- rand:: rngs:: StdRng :: from_entropy ( )
175
+ rand:: rngs:: StdRng :: from_os_rng ( )
184
176
}
185
177
186
178
/// Generates a random value using the thread-local random number generator.
@@ -194,7 +186,7 @@ pub fn std_rng_from_entropy(ambient_authority: AmbientAuthority) -> rngs::StdRng
194
186
#[ inline]
195
187
pub fn random < T > ( ambient_authority : AmbientAuthority ) -> T
196
188
where
197
- crate :: distributions :: Standard : crate :: distributions :: Distribution < T > ,
189
+ crate :: distr :: StandardUniform : crate :: distr :: Distribution < T > ,
198
190
{
199
191
let _ = ambient_authority;
200
192
rand:: random ( )
0 commit comments