from_rng should not consume its argument

This commit is contained in:
Diggory Hardy 2018-02-15 12:21:54 +00:00
parent 70e7e92cdf
commit 5e28ec9945
4 changed files with 6 additions and 6 deletions

View File

@ -804,7 +804,7 @@ pub trait SeedableRng: Sized {
/// [`NewRng`]: trait.NewRng.html
/// [`OsRng`]: os/struct.OsRng.html
/// [`XorShiftRng`]: prng/xorshift/struct.XorShiftRng.html
fn from_rng<R: Rng>(mut rng: R) -> Result<Self, Error> {
fn from_rng<R: Rng>(rng: &mut R) -> Result<Self, Error> {
let mut seed = Self::Seed::default();
rng.try_fill_bytes(seed.as_mut())?;
Ok(Self::from_seed(seed))
@ -844,7 +844,7 @@ pub trait NewRng: SeedableRng {
#[cfg(feature="std")]
impl<R: SeedableRng> NewRng for R {
fn new() -> Result<Self, Error> {
R::from_rng(EntropyRng::new())
R::from_rng(&mut EntropyRng::new())
}
}
@ -919,7 +919,7 @@ impl SeedableRng for StdRng {
StdRng(IsaacWordRng::from_seed(seed))
}
fn from_rng<R: Rng>(rng: R) -> Result<Self, Error> {
fn from_rng<R: Rng>(rng: &mut R) -> Result<Self, Error> {
IsaacWordRng::from_rng(rng).map(|rng| StdRng(rng))
}
}

View File

@ -347,7 +347,7 @@ impl SeedableRng for IsaacRng {
init(seed_extended, 2)
}
fn from_rng<R: Rng>(mut rng: R) -> Result<Self, Error> {
fn from_rng<R: Rng>(rng: &mut R) -> Result<Self, Error> {
// Custom `from_rng` implementation that fills a seed with the same size
// as the entire state.
let mut seed = [w(0u32); RAND_SIZE];

View File

@ -322,7 +322,7 @@ impl SeedableRng for Isaac64Rng {
init(seed_extended, 2)
}
fn from_rng<R: Rng>(mut rng: R) -> Result<Self, Error> {
fn from_rng<R: Rng>(rng: &mut R) -> Result<Self, Error> {
// Custom `from_rng` implementation that fills a seed with the same size
// as the entire state.
let mut seed = [w(0u64); RAND_SIZE];

View File

@ -102,7 +102,7 @@ impl SeedableRng for XorShiftRng {
}
}
fn from_rng<R: Rng>(mut rng: R) -> Result<Self, Error> {
fn from_rng<R: Rng>(rng: &mut R) -> Result<Self, Error> {
let mut seed_u32 = [0u32; 4];
loop {
unsafe {