24
24
html_playground_url = "https://play.rust-lang.org/" ,
25
25
test( attr( deny( warnings) ) ) ) ]
26
26
#![ deny( warnings) ]
27
+ #![ deny( missing_debug_implementations) ]
27
28
#![ no_std]
28
29
#![ unstable( feature = "rand" ,
29
30
reason = "use `rand` from crates.io" ,
32
33
#![ feature( staged_api) ]
33
34
#![ feature( step_by) ]
34
35
#![ feature( custom_attribute) ]
36
+ #![ feature( specialization) ]
35
37
#![ allow( unused_attributes) ]
36
38
37
39
#![ cfg_attr( not( test) , feature( core_float) ) ] // only necessary for no_std
43
45
#[ macro_use]
44
46
extern crate std;
45
47
48
+ use core:: fmt;
46
49
use core:: f64;
47
50
use core:: intrinsics;
48
51
use core:: marker:: PhantomData ;
@@ -288,6 +291,20 @@ impl<'a, T: Rand, R: Rng> Iterator for Generator<'a, T, R> {
288
291
}
289
292
}
290
293
294
+ impl < ' a , T , R > fmt:: Debug for Generator < ' a , T , R > {
295
+ default fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
296
+ f. pad ( "Generator { .. }" )
297
+ }
298
+ }
299
+
300
+ impl < ' a , T , R : fmt:: Debug > fmt:: Debug for Generator < ' a , T , R > {
301
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
302
+ f. debug_struct ( "Generator" )
303
+ . field ( "rng" , & self . rng )
304
+ . finish ( )
305
+ }
306
+ }
307
+
291
308
/// Iterator which will continuously generate random ascii characters.
292
309
///
293
310
/// This iterator is created via the `gen_ascii_chars` method on `Rng`.
@@ -306,6 +323,20 @@ impl<'a, R: Rng> Iterator for AsciiGenerator<'a, R> {
306
323
}
307
324
}
308
325
326
+ impl < ' a , R > fmt:: Debug for AsciiGenerator < ' a , R > {
327
+ default fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
328
+ f. pad ( "AsciiGenerator { .. }" )
329
+ }
330
+ }
331
+
332
+ impl < ' a , R : fmt:: Debug > fmt:: Debug for AsciiGenerator < ' a , R > {
333
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
334
+ f. debug_struct ( "AsciiGenerator" )
335
+ . field ( "rng" , & self . rng )
336
+ . finish ( )
337
+ }
338
+ }
339
+
309
340
/// A random number generator that can be explicitly seeded to produce
310
341
/// the same stream of randomness multiple times.
311
342
pub trait SeedableRng < Seed > : Rng {
@@ -326,7 +357,7 @@ pub trait SeedableRng<Seed>: Rng {
326
357
/// [1]: Marsaglia, George (July 2003). ["Xorshift
327
358
/// RNGs"](http://www.jstatsoft.org/v08/i14/paper). *Journal of
328
359
/// Statistical Software*. Vol. 8 (Issue 14).
329
- #[ derive( Clone ) ]
360
+ #[ derive( Clone , Debug ) ]
330
361
pub struct XorShiftRng {
331
362
x : u32 ,
332
363
y : u32 ,
@@ -415,6 +446,20 @@ impl Rand for XorShiftRng {
415
446
/// `[0,1)`.
416
447
pub struct Open01 < F > ( pub F ) ;
417
448
449
+ impl < F > fmt:: Debug for Open01 < F > {
450
+ default fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
451
+ f. pad ( "Open01 { .. }" )
452
+ }
453
+ }
454
+
455
+ impl < F : fmt:: Debug > fmt:: Debug for Open01 < F > {
456
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
457
+ f. debug_tuple ( "Open01" )
458
+ . field ( & self . 0 )
459
+ . finish ( )
460
+ }
461
+ }
462
+
418
463
/// A wrapper for generating floating point numbers uniformly in the
419
464
/// closed interval `[0,1]` (including both endpoints).
420
465
///
@@ -423,6 +468,20 @@ pub struct Open01<F>(pub F);
423
468
/// `[0,1)`.
424
469
pub struct Closed01 < F > ( pub F ) ;
425
470
471
+ impl < F > fmt:: Debug for Closed01 < F > {
472
+ default fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
473
+ f. pad ( "Closed01 { .. }" )
474
+ }
475
+ }
476
+
477
+ impl < F : fmt:: Debug > fmt:: Debug for Closed01 < F > {
478
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
479
+ f. debug_tuple ( "Closed01" )
480
+ . field ( & self . 0 )
481
+ . finish ( )
482
+ }
483
+ }
484
+
426
485
#[ cfg( test) ]
427
486
mod test {
428
487
use std:: __rand as rand;
0 commit comments