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