Skip to content

Commit a18d090

Browse files
author
Jorge Aparicio
committed
librand: use #[deriving(Copy)]
1 parent e0a88a7 commit a18d090

File tree

6 files changed

+10
-20
lines changed

6 files changed

+10
-20
lines changed

src/librand/chacha.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@ const CHACHA_ROUNDS: uint = 20; // Cryptographically secure from 8 upwards as of
2929
/// [1]: D. J. Bernstein, [*ChaCha, a variant of
3030
/// Salsa20*](http://cr.yp.to/chacha.html)
3131
32+
#[deriving(Copy)]
3233
pub struct ChaChaRng {
3334
buffer: [u32, ..STATE_WORDS], // Internal buffer of output
3435
state: [u32, ..STATE_WORDS], // Initial state
3536
index: uint, // Index into state
3637
}
3738

38-
impl Copy for ChaChaRng {}
39-
4039
static EMPTY: ChaChaRng = ChaChaRng {
4140
buffer: [0, ..STATE_WORDS],
4241
state: [0, ..STATE_WORDS],

src/librand/distributions/exponential.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
//! The exponential distribution.
1212
13-
use core::kinds::Copy;
1413
use core::num::Float;
1514

1615
use {Rng, Rand};
@@ -30,10 +29,9 @@ use distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample};
3029
/// Generate Normal Random
3130
/// Samples*](http://www.doornik.com/research/ziggurat.pdf). Nuffield
3231
/// College, Oxford
32+
#[deriving(Copy)]
3333
pub struct Exp1(pub f64);
3434

35-
impl Copy for Exp1 {}
36-
3735
// This could be done via `-rng.gen::<f64>().ln()` but that is slower.
3836
impl Rand for Exp1 {
3937
#[inline]
@@ -69,13 +67,12 @@ impl Rand for Exp1 {
6967
/// let v = exp.ind_sample(&mut rand::task_rng());
7068
/// println!("{} is from a Exp(2) distribution", v);
7169
/// ```
70+
#[deriving(Copy)]
7271
pub struct Exp {
7372
/// `lambda` stored as `1/lambda`, since this is what we scale by.
7473
lambda_inverse: f64
7574
}
7675

77-
impl Copy for Exp {}
78-
7976
impl Exp {
8077
/// Construct a new `Exp` with the given shape parameter
8178
/// `lambda`. Panics if `lambda <= 0`.

src/librand/distributions/normal.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
//! The normal and derived distributions.
1212
13-
use core::kinds::Copy;
1413
use core::num::Float;
1514

1615
use {Rng, Rand, Open01};
@@ -29,10 +28,9 @@ use distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample};
2928
/// Generate Normal Random
3029
/// Samples*](http://www.doornik.com/research/ziggurat.pdf). Nuffield
3130
/// College, Oxford
31+
#[deriving(Copy)]
3232
pub struct StandardNormal(pub f64);
3333

34-
impl Copy for StandardNormal {}
35-
3634
impl Rand for StandardNormal {
3735
fn rand<R:Rng>(rng: &mut R) -> StandardNormal {
3836
#[inline]
@@ -86,13 +84,12 @@ impl Rand for StandardNormal {
8684
/// let v = normal.ind_sample(&mut rand::task_rng());
8785
/// println!("{} is from a N(2, 9) distribution", v)
8886
/// ```
87+
#[deriving(Copy)]
8988
pub struct Normal {
9089
mean: f64,
9190
std_dev: f64,
9291
}
9392

94-
impl Copy for Normal {}
95-
9693
impl Normal {
9794
/// Construct a new `Normal` distribution with the given mean and
9895
/// standard deviation.
@@ -135,12 +132,11 @@ impl IndependentSample<f64> for Normal {
135132
/// let v = log_normal.ind_sample(&mut rand::task_rng());
136133
/// println!("{} is from an ln N(2, 9) distribution", v)
137134
/// ```
135+
#[deriving(Copy)]
138136
pub struct LogNormal {
139137
norm: Normal
140138
}
141139

142-
impl Copy for LogNormal {}
143-
144140
impl LogNormal {
145141
/// Construct a new `LogNormal` distribution with the given mean
146142
/// and standard deviation.

src/librand/isaac.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const RAND_SIZE_UINT: uint = 1 << (RAND_SIZE_LEN as uint);
2929
///
3030
/// [1]: Bob Jenkins, [*ISAAC: A fast cryptographic random number
3131
/// generator*](http://www.burtleburtle.net/bob/rand/isaacafa.html)
32+
#[deriving(Copy)]
3233
pub struct IsaacRng {
3334
cnt: u32,
3435
rsl: [u32, ..RAND_SIZE_UINT],
@@ -38,8 +39,6 @@ pub struct IsaacRng {
3839
c: u32
3940
}
4041

41-
impl Copy for IsaacRng {}
42-
4342
static EMPTY: IsaacRng = IsaacRng {
4443
cnt: 0,
4544
rsl: [0, ..RAND_SIZE_UINT],
@@ -265,6 +264,7 @@ const RAND_SIZE_64: uint = 1 << RAND_SIZE_64_LEN;
265264
///
266265
/// [1]: Bob Jenkins, [*ISAAC: A fast cryptographic random number
267266
/// generator*](http://www.burtleburtle.net/bob/rand/isaacafa.html)
267+
#[deriving(Copy)]
268268
pub struct Isaac64Rng {
269269
cnt: uint,
270270
rsl: [u64, .. RAND_SIZE_64],
@@ -274,8 +274,6 @@ pub struct Isaac64Rng {
274274
c: u64,
275275
}
276276

277-
impl Copy for Isaac64Rng {}
278-
279277
static EMPTY_64: Isaac64Rng = Isaac64Rng {
280278
cnt: 0,
281279
rsl: [0, .. RAND_SIZE_64],

src/librand/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ pub struct Closed01<F>(pub F);
501501
#[cfg(not(test))]
502502
mod std {
503503
pub use core::{option, fmt}; // panic!()
504+
pub use core::kinds;
504505
}
505506

506507
#[cfg(test)]

src/librand/reseeding.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,9 @@ pub trait Reseeder<R> {
133133

134134
/// Reseed an RNG using a `Default` instance. This reseeds by
135135
/// replacing the RNG with the result of a `Default::default` call.
136+
#[deriving(Copy)]
136137
pub struct ReseedWithDefault;
137138

138-
impl Copy for ReseedWithDefault {}
139-
140139
impl<R: Rng + Default> Reseeder<R> for ReseedWithDefault {
141140
fn reseed(&mut self, rng: &mut R) {
142141
*rng = Default::default();

0 commit comments

Comments
 (0)