@@ -26,7 +26,9 @@ use std::fmt::{ Debug, Formatter };
26
26
use std:: cell:: RefCell ;
27
27
use std:: rc:: Rc ;
28
28
29
- use rand:: { Rand , Rng } ;
29
+ use rand:: Rng ;
30
+ use rand:: distributions:: { Distribution , Standard } ;
31
+ use rand:: seq:: SliceRandom ;
30
32
31
33
pub use bytes:: compress:: Compression ;
32
34
@@ -163,9 +165,9 @@ impl CompressionTarget {
163
165
164
166
/// Support picking a random compression target.
165
167
/// Used for testing.
166
- impl Rand for CompressionTarget {
167
- fn rand < R : Rng > ( rng : & mut R ) -> Self {
168
- Self :: new ( Compression :: rand ( rng) )
168
+ impl Distribution < CompressionTarget > for Standard {
169
+ fn sample < R : Rng + ? Sized > ( & self , rng : & mut R ) -> CompressionTarget {
170
+ CompressionTarget :: new ( rng. gen ( ) )
169
171
}
170
172
}
171
173
impl std:: io:: Write for CompressionTarget {
@@ -213,27 +215,27 @@ pub enum Format {
213
215
214
216
/// Support picking a random format.
215
217
/// Used for testing.
216
- impl Rand for Format {
217
- fn rand < ' a , R : Rng > ( rng : & ' a mut R ) -> Self {
218
+ impl Distribution < Format > for Standard {
219
+ fn sample < ' a , R : Rng + ? Sized > ( & self , rng : & ' a mut R ) -> Format {
218
220
let generators = [
219
- Rc :: new ( |_| Self :: simple ( ) ) as Rc < Fn ( & ' a mut R ) -> Format > ,
221
+ Rc :: new ( |_| Format :: simple ( ) ) as Rc < Fn ( & ' a mut R ) -> Format > ,
220
222
Rc :: new ( |rng| {
221
223
use multipart:: { Statistics , Targets } ;
222
224
let stats = Rc :: new ( RefCell :: new ( Statistics :: default ( )
223
225
. with_source_bytes ( 0 ) ) ) ;
224
226
225
227
Format :: Multipart {
226
228
targets : Targets {
227
- strings_table : CompressionTarget :: rand ( rng) ,
228
- grammar_table : CompressionTarget :: rand ( rng) ,
229
- tree : CompressionTarget :: rand ( rng) ,
229
+ strings_table : rng. gen ( ) ,
230
+ grammar_table : rng. gen ( ) ,
231
+ tree : rng. gen ( ) ,
230
232
} ,
231
233
stats
232
234
}
233
235
} ) ,
234
236
Rc :: new ( |_| Format :: XML ) ,
235
237
] ;
236
- let pick : Rc < Fn ( & ' a mut R ) -> Format > = rng . choose ( & generators )
238
+ let pick : Rc < Fn ( & ' a mut R ) -> Format > = generators . choose ( rng )
237
239
. map ( Rc :: clone)
238
240
. unwrap ( ) ; // Never empty
239
241
pick ( rng)
@@ -254,9 +256,9 @@ impl Format {
254
256
Format :: Multipart { stats, .. } =>
255
257
Format :: Multipart {
256
258
targets : multipart:: Targets {
257
- strings_table : CompressionTarget :: rand ( rng) ,
258
- grammar_table : CompressionTarget :: rand ( rng) ,
259
- tree : CompressionTarget :: rand ( rng) ,
259
+ strings_table : rng. gen ( ) ,
260
+ grammar_table : rng. gen ( ) ,
261
+ tree : rng. gen ( ) ,
260
262
} ,
261
263
stats
262
264
}
0 commit comments