2020//! struct MyRngCore;
2121//!
2222//! impl Generator for MyRngCore {
23- //! type Results = [u32; 16];
23+ //! type Output = [u32; 16];
2424//!
25- //! fn generate(&mut self, results : &mut Self::Results ) {
25+ //! fn generate(&mut self, output : &mut Self::Output ) {
2626//! unimplemented!()
2727//! }
2828//! }
@@ -50,12 +50,15 @@ use core::fmt;
5050
5151/// A random (block) generator
5252pub trait Generator {
53- /// Results type. This is the 'block' an RNG implementing `BlockRngCore`
54- /// generates, which will usually be an array like `[u32; 16]`.
55- type Results ;
53+ /// The output type.
54+ ///
55+ /// For use with [`rand_core::block`](crate::block) code this must be `[u32; _]` or `[u64; _]`.
56+ type Output ;
5657
57- /// Generate a new block of results.
58- fn generate ( & mut self , results : & mut Self :: Results ) ;
58+ /// Generate a new block of `output`.
59+ ///
60+ /// This must fill `output` with random data.
61+ fn generate ( & mut self , output : & mut Self :: Output ) ;
5962}
6063
6164/// A cryptographically secure generator
@@ -105,14 +108,14 @@ pub trait CryptoGenerator: Generator {}
105108/// [`fill_bytes`]: RngCore::fill_bytes
106109#[ derive( Clone ) ]
107110pub struct BlockRng < R : Generator > {
108- results : R :: Results ,
111+ results : R :: Output ,
109112 index : usize ,
110113 /// The *core* part of the RNG, implementing the `generate` function.
111114 pub core : R ,
112115}
113116
114117// Custom Debug implementation that does not expose the contents of `results`.
115- impl < const N : usize , R : Generator < Results = [ u32 ; N ] > + fmt:: Debug > fmt:: Debug for BlockRng < R > {
118+ impl < const N : usize , R : Generator < Output = [ u32 ; N ] > + fmt:: Debug > fmt:: Debug for BlockRng < R > {
116119 fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
117120 fmt. debug_struct ( "BlockRng" )
118121 . field ( "core" , & self . core )
@@ -122,7 +125,7 @@ impl<const N: usize, R: Generator<Results = [u32; N]> + fmt::Debug> fmt::Debug f
122125 }
123126}
124127
125- impl < const N : usize , R : Generator < Results = [ u32 ; N ] > > BlockRng < R > {
128+ impl < const N : usize , R : Generator < Output = [ u32 ; N ] > > BlockRng < R > {
126129 /// Create a new `BlockRng` from an existing RNG implementing
127130 /// `Generator`. Results will be generated on first use.
128131 #[ inline]
@@ -161,7 +164,7 @@ impl<const N: usize, R: Generator<Results = [u32; N]>> BlockRng<R> {
161164 }
162165}
163166
164- impl < const N : usize , R : Generator < Results = [ u32 ; N ] > > RngCore for BlockRng < R > {
167+ impl < const N : usize , R : Generator < Output = [ u32 ; N ] > > RngCore for BlockRng < R > {
165168 #[ inline]
166169 fn next_u32 ( & mut self ) -> u32 {
167170 if self . index >= self . results . as_ref ( ) . len ( ) {
@@ -214,7 +217,7 @@ impl<const N: usize, R: Generator<Results = [u32; N]>> RngCore for BlockRng<R> {
214217 }
215218}
216219
217- impl < const N : usize , R : Generator < Results = [ u32 ; N ] > + SeedableRng > SeedableRng for BlockRng < R > {
220+ impl < const N : usize , R : Generator < Output = [ u32 ; N ] > + SeedableRng > SeedableRng for BlockRng < R > {
218221 type Seed = R :: Seed ;
219222
220223 #[ inline( always) ]
@@ -238,7 +241,7 @@ impl<const N: usize, R: Generator<Results = [u32; N]> + SeedableRng> SeedableRng
238241 }
239242}
240243
241- impl < const N : usize , R : CryptoGenerator < Results = [ u32 ; N ] > > CryptoRng for BlockRng < R > { }
244+ impl < const N : usize , R : CryptoGenerator < Output = [ u32 ; N ] > > CryptoRng for BlockRng < R > { }
242245
243246/// A wrapper type implementing [`RngCore`] for some type implementing
244247/// [`Generator`] with `u64` array buffer; i.e. this can be used to implement
@@ -262,15 +265,15 @@ impl<const N: usize, R: CryptoGenerator<Results = [u32; N]>> CryptoRng for Block
262265/// [`fill_bytes`]: RngCore::fill_bytes
263266#[ derive( Clone ) ]
264267pub struct BlockRng64 < R : Generator + ?Sized > {
265- results : R :: Results ,
268+ results : R :: Output ,
266269 index : usize ,
267270 half_used : bool , // true if only half of the previous result is used
268271 /// The *core* part of the RNG, implementing the `generate` function.
269272 pub core : R ,
270273}
271274
272275// Custom Debug implementation that does not expose the contents of `results`.
273- impl < const N : usize , R : Generator < Results = [ u64 ; N ] > + fmt:: Debug > fmt:: Debug for BlockRng64 < R > {
276+ impl < const N : usize , R : Generator < Output = [ u64 ; N ] > + fmt:: Debug > fmt:: Debug for BlockRng64 < R > {
274277 fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
275278 fmt. debug_struct ( "BlockRng64" )
276279 . field ( "core" , & self . core )
@@ -281,7 +284,7 @@ impl<const N: usize, R: Generator<Results = [u64; N]> + fmt::Debug> fmt::Debug f
281284 }
282285}
283286
284- impl < const N : usize , R : Generator < Results = [ u64 ; N ] > > BlockRng64 < R > {
287+ impl < const N : usize , R : Generator < Output = [ u64 ; N ] > > BlockRng64 < R > {
285288 /// Create a new `BlockRng` from an existing RNG implementing
286289 /// `Generator`. Results will be generated on first use.
287290 #[ inline]
@@ -324,7 +327,7 @@ impl<const N: usize, R: Generator<Results = [u64; N]>> BlockRng64<R> {
324327 }
325328}
326329
327- impl < const N : usize , R : Generator < Results = [ u64 ; N ] > > RngCore for BlockRng64 < R > {
330+ impl < const N : usize , R : Generator < Output = [ u64 ; N ] > > RngCore for BlockRng64 < R > {
328331 #[ inline]
329332 fn next_u32 ( & mut self ) -> u32 {
330333 let mut index = self . index - self . half_used as usize ;
@@ -376,7 +379,7 @@ impl<const N: usize, R: Generator<Results = [u64; N]>> RngCore for BlockRng64<R>
376379 }
377380}
378381
379- impl < const N : usize , R : Generator < Results = [ u64 ; N ] > + SeedableRng > SeedableRng for BlockRng64 < R > {
382+ impl < const N : usize , R : Generator < Output = [ u64 ; N ] > + SeedableRng > SeedableRng for BlockRng64 < R > {
380383 type Seed = R :: Seed ;
381384
382385 #[ inline( always) ]
@@ -400,7 +403,7 @@ impl<const N: usize, R: Generator<Results = [u64; N]> + SeedableRng> SeedableRng
400403 }
401404}
402405
403- impl < const N : usize , R : CryptoGenerator < Results = [ u64 ; N ] > > CryptoRng for BlockRng64 < R > { }
406+ impl < const N : usize , R : CryptoGenerator < Output = [ u64 ; N ] > > CryptoRng for BlockRng64 < R > { }
404407
405408#[ cfg( test) ]
406409mod test {
@@ -413,11 +416,11 @@ mod test {
413416 }
414417
415418 impl Generator for DummyRng {
416- type Results = [ u32 ; 16 ] ;
419+ type Output = [ u32 ; 16 ] ;
417420
418- fn generate ( & mut self , results : & mut Self :: Results ) {
419- for r in results {
420- * r = self . counter ;
421+ fn generate ( & mut self , output : & mut Self :: Output ) {
422+ for item in output {
423+ * item = self . counter ;
421424 self . counter = self . counter . wrapping_add ( 3511615421 ) ;
422425 }
423426 }
@@ -463,11 +466,11 @@ mod test {
463466 }
464467
465468 impl Generator for DummyRng64 {
466- type Results = [ u64 ; 8 ] ;
469+ type Output = [ u64 ; 8 ] ;
467470
468- fn generate ( & mut self , results : & mut Self :: Results ) {
469- for r in results {
470- * r = self . counter ;
471+ fn generate ( & mut self , output : & mut Self :: Output ) {
472+ for item in output {
473+ * item = self . counter ;
471474 self . counter = self . counter . wrapping_add ( 2781463553396133981 ) ;
472475 }
473476 }
0 commit comments