@@ -501,11 +501,8 @@ pub trait Rng {
501
501
///
502
502
/// [`ErrorKind`]: enum.ErrorKind.html
503
503
fn fill < T : AsByteSliceMut + ?Sized > ( & mut self , dest : & mut T ) where Self : Sized {
504
- let slice = dest. as_byte_slice_mut ( ) ;
505
- self . fill_bytes ( slice) ;
506
- for mut x in slice {
507
- x. to_le ( ) ;
508
- }
504
+ self . fill_bytes ( dest. as_byte_slice_mut ( ) ) ;
505
+ dest. to_le ( ) ;
509
506
}
510
507
511
508
/// Fill `dest` entirely with random data.
@@ -535,11 +532,8 @@ pub trait Rng {
535
532
///
536
533
/// [`ErrorKind`]: enum.ErrorKind.html
537
534
fn try_fill < T : AsByteSliceMut + ?Sized > ( & mut self , dest : & mut T ) -> Result < ( ) , Error > where Self : Sized {
538
- let slice = dest. as_byte_slice_mut ( ) ;
539
- self . try_fill_bytes ( slice) ?;
540
- for mut x in slice {
541
- x. to_le ( ) ;
542
- }
535
+ self . try_fill_bytes ( dest. as_byte_slice_mut ( ) ) ?;
536
+ dest. to_le ( ) ;
543
537
Ok ( ( ) )
544
538
}
545
539
@@ -766,12 +760,17 @@ impl<R: ?Sized> Rng for Box<R> where R: Rng {
766
760
pub trait AsByteSliceMut {
767
761
/// Return a mutable reference to self as a byte slice
768
762
fn as_byte_slice_mut < ' a > ( & ' a mut self ) -> & ' a mut [ u8 ] ;
763
+
764
+ /// Call `to_le` on each element (i.e. byte-swap on Big Endian platforms).
765
+ fn to_le ( & mut self ) ;
769
766
}
770
767
771
768
impl AsByteSliceMut for [ u8 ] {
772
769
fn as_byte_slice_mut < ' a > ( & ' a mut self ) -> & ' a mut [ u8 ] {
773
770
self
774
771
}
772
+
773
+ fn to_le ( & mut self ) { }
775
774
}
776
775
777
776
macro_rules! impl_as_byte_slice {
@@ -786,6 +785,12 @@ macro_rules! impl_as_byte_slice {
786
785
)
787
786
}
788
787
}
788
+
789
+ fn to_le( & mut self ) {
790
+ for mut x in self {
791
+ * x = x. to_le( ) ;
792
+ }
793
+ }
789
794
}
790
795
}
791
796
}
0 commit comments