Skip to content

Commit

Permalink
rand_core: add impl<R: Rng> Rng for &mut R
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Sep 14, 2017
1 parent 67b22bd commit ec70309
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion rand_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,27 @@ pub trait Rng {
fn try_fill(&mut self, dest: &mut [u8]) -> Result<()>;
}

impl<'a, R: Rng+?Sized> Rng for &'a mut R {
fn next_u32(&mut self) -> u32 {
(**self).next_u32()
}

fn next_u64(&mut self) -> u64 {
(**self).next_u64()
}

#[cfg(feature = "i128_support")]
fn next_u128(&mut self) -> u128 {
(**self).next_u128()
}

fn try_fill(&mut self, dest: &mut [u8]) -> Result<()> {
(**self).try_fill(dest)
}
}

#[cfg(feature="std")]
impl<R> Rng for Box<R> where R: Rng+?Sized {
impl<R: Rng+?Sized> Rng for Box<R> {
fn next_u32(&mut self) -> u32 {
(**self).next_u32()
}
Expand Down

0 comments on commit ec70309

Please sign in to comment.