diff --git a/src/librand/distributions/mod.rs b/src/librand/distributions/mod.rs index d1d24cea8714..5a85552dc384 100644 --- a/src/librand/distributions/mod.rs +++ b/src/librand/distributions/mod.rs @@ -21,6 +21,7 @@ use core::prelude::*; use core::num::{Float, Int}; +use core::marker::PhantomData; use {Rng, Rand}; @@ -56,7 +57,13 @@ pub trait IndependentSample: Sample { /// A wrapper for generating types that implement `Rand` via the /// `Sample` & `IndependentSample` traits. -pub struct RandSample; +pub struct RandSample { _marker: PhantomData } + +impl RandSample { + pub fn new() -> RandSample { + RandSample { _marker: PhantomData } + } +} impl Sample for RandSample { fn sample(&mut self, rng: &mut R) -> Sup { self.ind_sample(rng) } @@ -285,7 +292,7 @@ mod tests { #[test] fn test_rand_sample() { - let mut rand_sample = RandSample::; + let mut rand_sample = RandSample::::new(); assert_eq!(rand_sample.sample(&mut ::test::rng()), ConstRand(0)); assert_eq!(rand_sample.ind_sample(&mut ::test::rng()), ConstRand(0)); diff --git a/src/librand/lib.rs b/src/librand/lib.rs index 915c70bbf8ce..7588bf7c5158 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -41,6 +41,7 @@ extern crate core; #[cfg(test)] #[macro_use] extern crate log; use core::prelude::*; +use core::marker::PhantomData; pub use isaac::{IsaacRng, Isaac64Rng}; pub use chacha::ChaChaRng; @@ -206,7 +207,7 @@ pub trait Rng : Sized { /// .collect::>()); /// ``` fn gen_iter<'a, T: Rand>(&'a mut self) -> Generator<'a, T, Self> { - Generator { rng: self } + Generator { rng: self, _marker: PhantomData } } /// Generate a random value in the range [`low`, `high`). @@ -317,6 +318,7 @@ pub trait Rng : Sized { /// This iterator is created via the `gen_iter` method on `Rng`. pub struct Generator<'a, T, R:'a> { rng: &'a mut R, + _marker: PhantomData } impl<'a, T: Rand, R: Rng> Iterator for Generator<'a, T, R> {