@@ -491,9 +491,12 @@ pub trait Rng {
491
491
/// ```
492
492
///
493
493
/// [`ErrorKind`]: enum.ErrorKind.html
494
- fn fill < T : AsByteSlice + ?Sized > ( & mut self , dest : & mut T ) where Self : Sized {
495
- self . fill_bytes ( dest. as_byte_slice ( ) ) ;
496
- dest. to_le ( ) ;
494
+ fn fill < T : AsByteSliceMut + ?Sized > ( & mut self , dest : & mut T ) where Self : Sized {
495
+ let slice = dest. as_byte_slice_mut ( ) ;
496
+ self . fill_bytes ( slice) ;
497
+ for mut x in slice {
498
+ x. to_le ( ) ;
499
+ }
497
500
}
498
501
499
502
/// Fill `dest` entirely with random data.
@@ -522,9 +525,12 @@ pub trait Rng {
522
525
/// ```
523
526
///
524
527
/// [`ErrorKind`]: enum.ErrorKind.html
525
- fn try_fill < T : AsByteSlice + ?Sized > ( & mut self , dest : & mut T ) -> Result < ( ) , Error > where Self : Sized {
526
- self . try_fill_bytes ( dest. as_byte_slice ( ) ) ?;
527
- dest. to_le ( ) ;
528
+ fn try_fill < T : AsByteSliceMut + ?Sized > ( & mut self , dest : & mut T ) -> Result < ( ) , Error > where Self : Sized {
529
+ let slice = dest. as_byte_slice_mut ( ) ;
530
+ self . try_fill_bytes ( slice) ?;
531
+ for mut x in slice {
532
+ x. to_le ( ) ;
533
+ }
528
534
Ok ( ( ) )
529
535
}
530
536
@@ -747,24 +753,21 @@ impl<R: ?Sized> Rng for Box<R> where R: Rng {
747
753
}
748
754
749
755
/// Trait for casting types to byte slices
750
- pub trait AsByteSlice {
756
+ pub trait AsByteSliceMut {
751
757
/// Return a mutable reference to self as a byte slice
752
- fn as_byte_slice < ' a > ( & ' a mut self ) -> & ' a mut [ u8 ] ;
753
- /// Perform byte-swapping on BE platforms
754
- fn to_le ( & mut self ) ;
758
+ fn as_byte_slice_mut < ' a > ( & ' a mut self ) -> & ' a mut [ u8 ] ;
755
759
}
756
760
757
- impl AsByteSlice for [ u8 ] {
758
- fn as_byte_slice < ' a > ( & ' a mut self ) -> & ' a mut [ u8 ] {
761
+ impl AsByteSliceMut for [ u8 ] {
762
+ fn as_byte_slice_mut < ' a > ( & ' a mut self ) -> & ' a mut [ u8 ] {
759
763
self
760
764
}
761
- fn to_le ( & mut self ) { }
762
765
}
763
766
764
767
macro_rules! impl_as_byte_slice {
765
768
( $t: ty) => {
766
- impl AsByteSlice for [ $t] {
767
- fn as_byte_slice <' a>( & ' a mut self ) -> & ' a mut [ u8 ] {
769
+ impl AsByteSliceMut for [ $t] {
770
+ fn as_byte_slice_mut <' a>( & ' a mut self ) -> & ' a mut [ u8 ] {
768
771
unsafe {
769
772
slice:: from_raw_parts_mut( & mut self [ 0 ]
770
773
as * mut $t
@@ -773,11 +776,6 @@ macro_rules! impl_as_byte_slice {
773
776
)
774
777
}
775
778
}
776
- fn to_le( & mut self ) {
777
- for mut x in self {
778
- x. to_le( ) ;
779
- }
780
- }
781
779
}
782
780
}
783
781
}
0 commit comments