@@ -87,8 +87,8 @@ pub trait BlockRngCore {
87
87
88
88
#[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
89
89
enum IndexLevel {
90
- Bit ,
91
- Byte ,
90
+ U1 ,
91
+ U8 ,
92
92
U32 ,
93
93
U64 ,
94
94
}
@@ -98,18 +98,18 @@ impl IndexLevel {
98
98
fn convert ( & mut self , index : usize , level : Self ) -> usize {
99
99
use IndexLevel :: * ;
100
100
let res = match ( * self , level) {
101
- ( Bit , Bit ) | ( Byte , Byte ) | ( U32 , U32 ) | ( U64 , U64 ) => return index,
102
- ( Bit , Byte ) => ( index / 8 ) + ( ( index & 0b111 ) != 0 ) as usize ,
103
- ( Bit , U32 ) => ( index / 32 ) + ( ( index & 0b1_1111 ) != 0 ) as usize ,
104
- ( Bit , U64 ) => ( index / 64 ) + ( ( index & 0b11_1111 ) != 0 ) as usize ,
105
- ( Byte , Bit ) => 8 * index,
106
- ( Byte , U32 ) => ( index / 4 ) + ( ( index & 0b11 ) != 0 ) as usize ,
107
- ( Byte , U64 ) => ( index / 8 ) + ( ( index & 0b111 ) != 0 ) as usize ,
108
- ( U32 , Bit ) => 32 * index,
109
- ( U32 , Byte ) => 4 * index,
101
+ ( U1 , U1 ) | ( U8 , U8 ) | ( U32 , U32 ) | ( U64 , U64 ) => return index,
102
+ ( U1 , U8 ) => ( index / 8 ) + ( ( index & 0b111 ) != 0 ) as usize ,
103
+ ( U1 , U32 ) => ( index / 32 ) + ( ( index & 0b1_1111 ) != 0 ) as usize ,
104
+ ( U1 , U64 ) => ( index / 64 ) + ( ( index & 0b11_1111 ) != 0 ) as usize ,
105
+ ( U8 , U1 ) => 8 * index,
106
+ ( U8 , U32 ) => ( index / 4 ) + ( ( index & 0b11 ) != 0 ) as usize ,
107
+ ( U8 , U64 ) => ( index / 8 ) + ( ( index & 0b111 ) != 0 ) as usize ,
108
+ ( U32 , U1 ) => 32 * index,
109
+ ( U32 , U8 ) => 4 * index,
110
110
( U32 , U64 ) => ( index / 2 ) + ( ( index & 0b1 ) != 0 ) as usize ,
111
- ( U64 , Bit ) => 64 * index,
112
- ( U64 , Byte ) => 8 * index,
111
+ ( U64 , U1 ) => 64 * index,
112
+ ( U64 , U8 ) => 8 * index,
113
113
( U64 , U32 ) => 2 * index,
114
114
} ;
115
115
* self = level;
@@ -167,8 +167,9 @@ impl<R: BlockRngCore + fmt::Debug> fmt::Debug for BlockRng<R> {
167
167
fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
168
168
fmt. debug_struct ( "BlockRng" )
169
169
. field ( "core" , & self . core )
170
- . field ( "result_len" , & self . results . as_ref ( ) . len ( ) )
170
+ . field ( "result_len" , & self . get_results_u8 ( ) . len ( ) )
171
171
. field ( "index" , & self . index )
172
+ . field ( "level" , & self . level )
172
173
. finish ( )
173
174
}
174
175
}
@@ -180,7 +181,7 @@ impl<R: BlockRngCore> BlockRng<R> {
180
181
pub fn new ( core : R ) -> BlockRng < R > {
181
182
let results = R :: Results :: default ( ) ;
182
183
let index = AsRef :: < [ u8 ] > :: as_ref ( & results) . len ( ) ;
183
- BlockRng { core, results, index, level : IndexLevel :: Byte }
184
+ BlockRng { core, results, index, level : IndexLevel :: U8 }
184
185
}
185
186
186
187
#[ inline( always) ]
@@ -205,7 +206,7 @@ where
205
206
{
206
207
#[ inline]
207
208
fn next_bool ( & mut self ) -> bool {
208
- let index = self . level . convert ( self . index , IndexLevel :: Bit ) ;
209
+ let index = self . level . convert ( self . index , IndexLevel :: U1 ) ;
209
210
match self . get_results_u8 ( ) . get ( index / 8 ) {
210
211
Some ( & v) => {
211
212
self . index = index + 1 ;
@@ -258,7 +259,7 @@ where
258
259
259
260
#[ inline]
260
261
fn try_fill_bytes ( & mut self , mut dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
261
- let index = self . level . convert ( self . index , IndexLevel :: Byte ) ;
262
+ let index = self . level . convert ( self . index , IndexLevel :: U8 ) ;
262
263
263
264
let rlen = self . get_results_u8 ( ) . len ( ) ;
264
265
if index < rlen {
0 commit comments