@@ -71,31 +71,39 @@ pub fn fill_bytes_via_next<R: RngCore + ?Sized>(rng: &mut R, dest: &mut [u8]) {
7171 }
7272}
7373
74- pub ( crate ) trait Observable : Copy {
75- type Bytes : Sized + AsRef < [ u8 ] > ;
76- fn to_le_bytes ( self ) -> Self :: Bytes ;
77- }
78- impl Observable for u32 {
79- type Bytes = [ u8 ; 4 ] ;
74+ mod sealed {
75+ pub trait Word : Copy {
76+ type Bytes : Sized + AsRef < [ u8 ] > ;
77+ fn to_le_bytes ( self ) -> Self :: Bytes ;
78+ }
79+ impl Word for u32 {
80+ type Bytes = [ u8 ; 4 ] ;
8081
81- fn to_le_bytes ( self ) -> Self :: Bytes {
82- Self :: to_le_bytes ( self )
82+ fn to_le_bytes ( self ) -> Self :: Bytes {
83+ Self :: to_le_bytes ( self )
84+ }
8385 }
84- }
85- impl Observable for u64 {
86- type Bytes = [ u8 ; 8 ] ;
86+ impl Word for u64 {
87+ type Bytes = [ u8 ; 8 ] ;
8788
88- fn to_le_bytes ( self ) -> Self :: Bytes {
89- Self :: to_le_bytes ( self )
89+ fn to_le_bytes ( self ) -> Self :: Bytes {
90+ Self :: to_le_bytes ( self )
91+ }
9092 }
9193}
9294
95+ /// A marker trait for supported word types
96+ ///
97+ /// This is implemented for: `u32`, `u64`.
98+ pub trait Word : sealed:: Word { }
99+ impl < W : sealed:: Word > Word for W { }
100+
93101/// Fill dest from src
94102///
95103/// Returns `(n, byte_len)`. `src[..n]` is consumed,
96104/// `dest[..byte_len]` is filled. `src[n..]` and `dest[byte_len..]` are left
97105/// unaltered.
98- pub ( crate ) fn fill_via_chunks < T : Observable > ( src : & [ T ] , dest : & mut [ u8 ] ) -> ( usize , usize ) {
106+ pub ( crate ) fn fill_via_chunks < T : Word > ( src : & [ T ] , dest : & mut [ u8 ] ) -> ( usize , usize ) {
99107 let size = core:: mem:: size_of :: < T > ( ) ;
100108
101109 // Always use little endian for portability of results.
0 commit comments