File tree Expand file tree Collapse file tree 4 files changed +20
-15
lines changed Expand file tree Collapse file tree 4 files changed +20
-15
lines changed Original file line number Diff line number Diff line change 12
12
13
13
use core:: prelude:: * ;
14
14
use core:: num:: Int ;
15
-
16
15
use { Rng , SeedableRng , Rand } ;
17
16
18
17
const KEY_WORDS : uint = 8 ; // 8 words for the 256-bit key
@@ -28,8 +27,7 @@ const CHACHA_ROUNDS: uint = 20; // Cryptographically secure from 8 upwards as of
28
27
///
29
28
/// [1]: D. J. Bernstein, [*ChaCha, a variant of
30
29
/// Salsa20*](http://cr.yp.to/chacha.html)
31
-
32
- #[ derive( Copy ) ]
30
+ #[ deriving( Copy , Clone ) ]
33
31
pub struct ChaChaRng {
34
32
buffer : [ u32 ; STATE_WORDS ] , // Internal buffer of output
35
33
state : [ u32 ; STATE_WORDS ] , // Initial state
Original file line number Diff line number Diff line change @@ -179,6 +179,13 @@ impl IsaacRng {
179
179
}
180
180
}
181
181
182
+ // Cannot be derived because [u32; 256] does not implement Clone
183
+ impl Clone for IsaacRng {
184
+ fn clone ( & self ) -> IsaacRng {
185
+ * self
186
+ }
187
+ }
188
+
182
189
impl Rng for IsaacRng {
183
190
#[ inline]
184
191
fn next_u32 ( & mut self ) -> u32 {
@@ -415,6 +422,13 @@ impl Isaac64Rng {
415
422
}
416
423
}
417
424
425
+ // Cannot be derived because [u32; 256] does not implement Clone
426
+ impl Clone for Isaac64Rng {
427
+ fn clone ( & self ) -> Isaac64Rng {
428
+ * self
429
+ }
430
+ }
431
+
418
432
impl Rng for Isaac64Rng {
419
433
// FIXME #7771: having next_u32 like this should be unnecessary
420
434
#[ inline]
@@ -485,6 +499,7 @@ impl Rand for Isaac64Rng {
485
499
}
486
500
}
487
501
502
+
488
503
#[ cfg( test) ]
489
504
mod test {
490
505
use std:: prelude:: v1:: * ;
Original file line number Diff line number Diff line change @@ -385,24 +385,14 @@ pub trait SeedableRng<Seed>: Rng {
385
385
/// RNGs"](http://www.jstatsoft.org/v08/i14/paper). *Journal of
386
386
/// Statistical Software*. Vol. 8 (Issue 14).
387
387
#[ allow( missing_copy_implementations) ]
388
+ #[ deriving( Clone ) ]
388
389
pub struct XorShiftRng {
389
390
x : u32 ,
390
391
y : u32 ,
391
392
z : u32 ,
392
393
w : u32 ,
393
394
}
394
395
395
- impl Clone for XorShiftRng {
396
- fn clone ( & self ) -> XorShiftRng {
397
- XorShiftRng {
398
- x : self . x ,
399
- y : self . y ,
400
- z : self . z ,
401
- w : self . w ,
402
- }
403
- }
404
- }
405
-
406
396
impl XorShiftRng {
407
397
/// Creates a new XorShiftRng instance which is not seeded.
408
398
///
@@ -507,6 +497,7 @@ pub struct Closed01<F>(pub F);
507
497
#[ cfg( not( test) ) ]
508
498
mod std {
509
499
pub use core:: { option, fmt} ; // panic!()
500
+ pub use core:: clone; // derive Clone
510
501
pub use core:: kinds;
511
502
}
512
503
Original file line number Diff line number Diff line change @@ -245,7 +245,7 @@ pub mod reader;
245
245
246
246
/// The standard RNG. This is designed to be efficient on the current
247
247
/// platform.
248
- #[ derive ( Copy ) ]
248
+ #[ deriving ( Copy , Clone ) ]
249
249
pub struct StdRng {
250
250
rng : IsaacWordRng ,
251
251
}
@@ -322,6 +322,7 @@ static THREAD_RNG_RESEED_THRESHOLD: uint = 32_768;
322
322
type ThreadRngInner = reseeding:: ReseedingRng < StdRng , ThreadRngReseeder > ;
323
323
324
324
/// The thread-local RNG.
325
+ #[ deriving( Clone ) ]
325
326
pub struct ThreadRng {
326
327
rng : Rc < RefCell < ThreadRngInner > > ,
327
328
}
You can’t perform that action at this time.
0 commit comments