Skip to content

Commit

Permalink
Use DerefMut instead of Box/&mut to re-implement RngCore
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Mar 9, 2018
1 parent 1c009af commit 87d3df8
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ extern crate stdweb;


use core::{marker, mem, slice};
#[cfg(all(feature="alloc", not(feature="std")))] use alloc::boxed::Box;
use core::ops::DerefMut;

// external rngs
pub use jitter::JitterRng;
Expand Down Expand Up @@ -740,30 +740,7 @@ pub trait Rng: RngCore {

impl<R: RngCore> Rng for R {}

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

#[inline]
fn next_u64(&mut self) -> u64 {
(**self).next_u64()
}

#[inline]
fn fill_bytes(&mut self, dest: &mut [u8]) {
(**self).fill_bytes(dest)
}

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

#[cfg(any(feature="std", feature="alloc"))]
impl<R: RngCore + ?Sized> RngCore for Box<R> {
impl<R: RngCore + ?Sized, T: DerefMut<Target = R>> RngCore for T {
#[inline]
fn next_u32(&mut self) -> u32 {
(**self).next_u32()
Expand Down

0 comments on commit 87d3df8

Please sign in to comment.