250
250
#[ cfg( feature="std" ) ] extern crate std as core;
251
251
#[ cfg( all( feature = "alloc" , not( feature="std" ) ) ) ] extern crate alloc;
252
252
253
- use core:: { marker, mem, slice } ;
253
+ use core:: { marker, mem} ;
254
254
#[ cfg( feature="std" ) ] use std:: cell:: RefCell ;
255
255
#[ cfg( feature="std" ) ] use std:: rc:: Rc ;
256
256
#[ cfg( all( feature="alloc" , not( feature="std" ) ) ) ] use alloc:: boxed:: Box ;
@@ -732,24 +732,6 @@ impl<'a, R: Rng> Iterator for AsciiGenerator<'a, R> {
732
732
}
733
733
}
734
734
735
- mod private {
736
- pub trait Sealed { }
737
- impl Sealed for [ u8 ; 4 ] { }
738
- impl Sealed for [ u8 ; 8 ] { }
739
- impl Sealed for [ u8 ; 12 ] { }
740
- impl Sealed for [ u8 ; 16 ] { }
741
- impl Sealed for [ u8 ; 24 ] { }
742
- impl Sealed for [ u8 ; 32 ] { }
743
- }
744
-
745
- /// The seed type is restricted to these types. This trait is sealed to prevent
746
- /// user-extension.
747
- ///
748
- /// Use of byte-arrays avoids endianness issues. We may extend this to allow
749
- /// byte arrays of other lengths in the future.
750
- pub trait SeedRestriction : private:: Sealed + Default + AsMut < [ u8 ] > { }
751
- impl < S > SeedRestriction for S where S : private:: Sealed + Default + AsMut < [ u8 ] > { }
752
-
753
735
/// A random number generator that can be explicitly seeded.
754
736
///
755
737
/// Each pseudo-random number generator (PRNG) should implement this.
@@ -762,7 +744,7 @@ pub trait SeedableRng: Sized {
762
744
/// RNG's with partially overlapping periods.
763
745
///
764
746
/// For cryptographic RNG's a seed of 256 bits is recommended, `[u8; 32]`.
765
- type Seed : SeedRestriction ;
747
+ type Seed : Sized + Default + AsMut < [ u8 ] > ;
766
748
767
749
/// Create a new PRNG using the given seed.
768
750
///
@@ -806,12 +788,7 @@ pub trait SeedableRng: Sized {
806
788
/// There are no reproducibility requirements like endianness conversion.
807
789
fn from_rng < R : Rng > ( mut rng : R ) -> Result < Self , Error > {
808
790
let mut seed = Self :: Seed :: default ( ) ;
809
- let size = mem:: size_of :: < Self :: Seed > ( ) as usize ;
810
- unsafe {
811
- let ptr = seed. as_mut ( ) . as_mut_ptr ( ) as * mut u8 ;
812
- let slice = slice:: from_raw_parts_mut ( ptr, size) ;
813
- rng. try_fill_bytes ( slice) ?;
814
- }
791
+ rng. try_fill_bytes ( seed. as_mut ( ) ) ?;
815
792
Ok ( Self :: from_seed ( seed) )
816
793
}
817
794
}
0 commit comments