]> git.lizzy.rs Git - rust.git/commitdiff
librand: use `#[deriving(Copy)]`
authorJorge Aparicio <japaricious@gmail.com>
Mon, 15 Dec 2014 03:45:18 +0000 (22:45 -0500)
committerJorge Aparicio <japaricious@gmail.com>
Fri, 19 Dec 2014 15:43:24 +0000 (10:43 -0500)
src/librand/chacha.rs
src/librand/distributions/exponential.rs
src/librand/distributions/normal.rs
src/librand/isaac.rs
src/librand/lib.rs
src/librand/reseeding.rs

index 5cbc5a0a61cc491b4e890786b5aad82bae209686..6fc92e1e94fcbdcbbedbf74b2e326b50bf8dff99 100644 (file)
 /// [1]: D. J. Bernstein, [*ChaCha, a variant of
 /// Salsa20*](http://cr.yp.to/chacha.html)
 
+#[deriving(Copy)]
 pub struct ChaChaRng {
     buffer:  [u32, ..STATE_WORDS], // Internal buffer of output
     state:   [u32, ..STATE_WORDS], // Initial state
     index:   uint,                 // Index into state
 }
 
-impl Copy for ChaChaRng {}
-
 static EMPTY: ChaChaRng = ChaChaRng {
     buffer:  [0, ..STATE_WORDS],
     state:   [0, ..STATE_WORDS],
index 9a9f31e9339c8e5240c693ab07e8320e8228f0a4..431a530726a083291ab0a38cf547e304d3d191cb 100644 (file)
@@ -10,7 +10,6 @@
 
 //! The exponential distribution.
 
-use core::kinds::Copy;
 use core::num::Float;
 
 use {Rng, Rand};
 /// Generate Normal Random
 /// Samples*](http://www.doornik.com/research/ziggurat.pdf). Nuffield
 /// College, Oxford
+#[deriving(Copy)]
 pub struct Exp1(pub f64);
 
-impl Copy for Exp1 {}
-
 // This could be done via `-rng.gen::<f64>().ln()` but that is slower.
 impl Rand for Exp1 {
     #[inline]
@@ -69,13 +67,12 @@ fn zero_case<R:Rng>(rng: &mut R, _u: f64) -> f64 {
 /// let v = exp.ind_sample(&mut rand::task_rng());
 /// println!("{} is from a Exp(2) distribution", v);
 /// ```
+#[deriving(Copy)]
 pub struct Exp {
     /// `lambda` stored as `1/lambda`, since this is what we scale by.
     lambda_inverse: f64
 }
 
-impl Copy for Exp {}
-
 impl Exp {
     /// Construct a new `Exp` with the given shape parameter
     /// `lambda`. Panics if `lambda <= 0`.
index f5261f1db82ee7b7ca08ea03e8539fa29aa0beec..16413af626739ed8fa65817f20d3aba8573359d3 100644 (file)
@@ -10,7 +10,6 @@
 
 //! The normal and derived distributions.
 
-use core::kinds::Copy;
 use core::num::Float;
 
 use {Rng, Rand, Open01};
 /// Generate Normal Random
 /// Samples*](http://www.doornik.com/research/ziggurat.pdf). Nuffield
 /// College, Oxford
+#[deriving(Copy)]
 pub struct StandardNormal(pub f64);
 
-impl Copy for StandardNormal {}
-
 impl Rand for StandardNormal {
     fn rand<R:Rng>(rng: &mut R) -> StandardNormal {
         #[inline]
@@ -86,13 +84,12 @@ fn zero_case<R:Rng>(rng: &mut R, u: f64) -> f64 {
 /// let v = normal.ind_sample(&mut rand::task_rng());
 /// println!("{} is from a N(2, 9) distribution", v)
 /// ```
+#[deriving(Copy)]
 pub struct Normal {
     mean: f64,
     std_dev: f64,
 }
 
-impl Copy for Normal {}
-
 impl Normal {
     /// Construct a new `Normal` distribution with the given mean and
     /// standard deviation.
@@ -135,12 +132,11 @@ fn ind_sample<R: Rng>(&self, rng: &mut R) -> f64 {
 /// let v = log_normal.ind_sample(&mut rand::task_rng());
 /// println!("{} is from an ln N(2, 9) distribution", v)
 /// ```
+#[deriving(Copy)]
 pub struct LogNormal {
     norm: Normal
 }
 
-impl Copy for LogNormal {}
-
 impl LogNormal {
     /// Construct a new `LogNormal` distribution with the given mean
     /// and standard deviation.
index 2499d7f529fd5183a76130e09da6c15919f87468..3cb1f51a6a80102d472271934b1d7780983c14bd 100644 (file)
@@ -29,6 +29,7 @@
 ///
 /// [1]: Bob Jenkins, [*ISAAC: A fast cryptographic random number
 /// generator*](http://www.burtleburtle.net/bob/rand/isaacafa.html)
+#[deriving(Copy)]
 pub struct IsaacRng {
     cnt: u32,
     rsl: [u32, ..RAND_SIZE_UINT],
@@ -38,8 +39,6 @@ pub struct IsaacRng {
     c: u32
 }
 
-impl Copy for IsaacRng {}
-
 static EMPTY: IsaacRng = IsaacRng {
     cnt: 0,
     rsl: [0, ..RAND_SIZE_UINT],
@@ -265,6 +264,7 @@ fn rand<R: Rng>(other: &mut R) -> IsaacRng {
 ///
 /// [1]: Bob Jenkins, [*ISAAC: A fast cryptographic random number
 /// generator*](http://www.burtleburtle.net/bob/rand/isaacafa.html)
+#[deriving(Copy)]
 pub struct Isaac64Rng {
     cnt: uint,
     rsl: [u64, .. RAND_SIZE_64],
@@ -274,8 +274,6 @@ pub struct Isaac64Rng {
     c: u64,
 }
 
-impl Copy for Isaac64Rng {}
-
 static EMPTY_64: Isaac64Rng = Isaac64Rng {
     cnt: 0,
     rsl: [0, .. RAND_SIZE_64],
index dfcdad481a91abf1c59d9ccb410c6df4b1c804a6..514ff81da518ec789c5614c169b197aa7a9887b0 100644 (file)
@@ -501,6 +501,7 @@ fn rand<R: Rng>(rng: &mut R) -> XorShiftRng {
 #[cfg(not(test))]
 mod std {
     pub use core::{option, fmt}; // panic!()
+    pub use core::kinds;
 }
 
 #[cfg(test)]
index 46ee67940f26997ed832cdb298bb24ce561de223..94a11c040e49758e7a8f34e1cafc7a84310b6aa1 100644 (file)
@@ -133,10 +133,9 @@ pub trait Reseeder<R> {
 
 /// Reseed an RNG using a `Default` instance. This reseeds by
 /// replacing the RNG with the result of a `Default::default` call.
+#[deriving(Copy)]
 pub struct ReseedWithDefault;
 
-impl Copy for ReseedWithDefault {}
-
 impl<R: Rng + Default> Reseeder<R> for ReseedWithDefault {
     fn reseed(&mut self, rng: &mut R) {
         *rng = Default::default();