Skip to content

Commit 5e28ec9

Browse files
committed
from_rng should not consume its argument
1 parent 70e7e92 commit 5e28ec9

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ pub trait SeedableRng: Sized {
804804
/// [`NewRng`]: trait.NewRng.html
805805
/// [`OsRng`]: os/struct.OsRng.html
806806
/// [`XorShiftRng`]: prng/xorshift/struct.XorShiftRng.html
807-
fn from_rng<R: Rng>(mut rng: R) -> Result<Self, Error> {
807+
fn from_rng<R: Rng>(rng: &mut R) -> Result<Self, Error> {
808808
let mut seed = Self::Seed::default();
809809
rng.try_fill_bytes(seed.as_mut())?;
810810
Ok(Self::from_seed(seed))
@@ -844,7 +844,7 @@ pub trait NewRng: SeedableRng {
844844
#[cfg(feature="std")]
845845
impl<R: SeedableRng> NewRng for R {
846846
fn new() -> Result<Self, Error> {
847-
R::from_rng(EntropyRng::new())
847+
R::from_rng(&mut EntropyRng::new())
848848
}
849849
}
850850

@@ -919,7 +919,7 @@ impl SeedableRng for StdRng {
919919
StdRng(IsaacWordRng::from_seed(seed))
920920
}
921921

922-
fn from_rng<R: Rng>(rng: R) -> Result<Self, Error> {
922+
fn from_rng<R: Rng>(rng: &mut R) -> Result<Self, Error> {
923923
IsaacWordRng::from_rng(rng).map(|rng| StdRng(rng))
924924
}
925925
}

src/prng/isaac.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl SeedableRng for IsaacRng {
347347
init(seed_extended, 2)
348348
}
349349

350-
fn from_rng<R: Rng>(mut rng: R) -> Result<Self, Error> {
350+
fn from_rng<R: Rng>(rng: &mut R) -> Result<Self, Error> {
351351
// Custom `from_rng` implementation that fills a seed with the same size
352352
// as the entire state.
353353
let mut seed = [w(0u32); RAND_SIZE];

src/prng/isaac64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ impl SeedableRng for Isaac64Rng {
322322
init(seed_extended, 2)
323323
}
324324

325-
fn from_rng<R: Rng>(mut rng: R) -> Result<Self, Error> {
325+
fn from_rng<R: Rng>(rng: &mut R) -> Result<Self, Error> {
326326
// Custom `from_rng` implementation that fills a seed with the same size
327327
// as the entire state.
328328
let mut seed = [w(0u64); RAND_SIZE];

src/prng/xorshift.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl SeedableRng for XorShiftRng {
102102
}
103103
}
104104

105-
fn from_rng<R: Rng>(mut rng: R) -> Result<Self, Error> {
105+
fn from_rng<R: Rng>(rng: &mut R) -> Result<Self, Error> {
106106
let mut seed_u32 = [0u32; 4];
107107
loop {
108108
unsafe {

0 commit comments

Comments
 (0)