Skip to content

Commit

Permalink
Use DerefMut instead of direct Box/&mut impls
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Mar 14, 2018
1 parent b9d885e commit 5ac9f54
Showing 1 changed file with 2 additions and 26 deletions.
28 changes: 2 additions & 26 deletions rand-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@

use core::default::Default;
use core::convert::AsMut;

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

pub use error::{ErrorKind, Error};

Expand Down Expand Up @@ -262,30 +261,7 @@ pub trait SeedableRng: Sized {
}


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 5ac9f54

Please sign in to comment.