Skip to content

Commit

Permalink
Remove unsafe from from_seed
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jan 18, 2018
1 parent b21d1a9 commit f97e698
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
#[cfg(feature="std")] extern crate std as core;
#[cfg(all(feature = "alloc", not(feature="std")))] extern crate alloc;

use core::{marker, mem, slice};
use core::{marker, mem};
#[cfg(feature="std")] use std::cell::RefCell;
#[cfg(feature="std")] use std::rc::Rc;
#[cfg(all(feature="alloc", not(feature="std")))] use alloc::boxed::Box;
Expand Down Expand Up @@ -762,7 +762,7 @@ pub trait SeedableRng: Sized {
/// RNG's with partially overlapping periods.
///
/// For cryptographic RNG's a seed of 256 bits is recommended, `[u8; 32]`.
type Seed: SeedRestriction;
type Seed: Sized + Default + AsMut<[u8]>;

/// Create a new PRNG using the given seed.
///
Expand Down Expand Up @@ -806,12 +806,7 @@ pub trait SeedableRng: Sized {
/// There are no reproducibility requirements like endianness conversion.
fn from_rng<R: Rng>(mut rng: R) -> Result<Self, Error> {
let mut seed = Self::Seed::default();
let size = mem::size_of::<Self::Seed>() as usize;
unsafe {
let ptr = seed.as_mut().as_mut_ptr() as *mut u8;
let slice = slice::from_raw_parts_mut(ptr, size);
rng.try_fill_bytes(slice)?;
}
rng.try_fill_bytes(seed.as_mut())?;
Ok(Self::from_seed(seed))
}
}
Expand Down

0 comments on commit f97e698

Please sign in to comment.