@@ -140,6 +140,9 @@ pub mod le;
140
140
/// [`next_u64`]: trait.RngCore.html#tymethod.next_u64
141
141
/// [`CryptoRng`]: trait.CryptoRng.html
142
142
pub trait RngCore {
143
+ // Type of the values natively generated by this RNG.
144
+ type Item ;
145
+
143
146
/// Return the next random `u32`.
144
147
///
145
148
/// RNGs must implement at least one method from this trait directly. In
@@ -186,6 +189,9 @@ pub trait RngCore {
186
189
///
187
190
/// [`fill_bytes`]: trait.RngCore.html#method.fill_bytes
188
191
fn try_fill_bytes ( & mut self , dest : & mut [ u8 ] ) -> Result < ( ) , Error > ;
192
+
193
+ /// Return a native value
194
+ fn next ( & mut self ) -> Self :: Item ;
189
195
}
190
196
191
197
/// A trait for RNGs which do not generate random numbers individually, but in
@@ -349,6 +355,8 @@ pub trait SeedableRng: Sized {
349
355
350
356
351
357
impl < ' a , R : RngCore + ?Sized > RngCore for & ' a mut R {
358
+ type Item = R :: Item ;
359
+
352
360
#[ inline( always) ]
353
361
fn next_u32 ( & mut self ) -> u32 {
354
362
( * * self ) . next_u32 ( )
@@ -366,10 +374,16 @@ impl<'a, R: RngCore + ?Sized> RngCore for &'a mut R {
366
374
fn try_fill_bytes ( & mut self , dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
367
375
( * * self ) . try_fill_bytes ( dest)
368
376
}
377
+
378
+ fn next ( & mut self ) -> Self :: Item {
379
+ ( * * self ) . next ( )
380
+ }
369
381
}
370
382
371
383
#[ cfg( feature="alloc" ) ]
372
384
impl < R : RngCore + ?Sized > RngCore for Box < R > {
385
+ type Item = R :: Item ;
386
+
373
387
#[ inline( always) ]
374
388
fn next_u32 ( & mut self ) -> u32 {
375
389
( * * self ) . next_u32 ( )
@@ -387,4 +401,8 @@ impl<R: RngCore + ?Sized> RngCore for Box<R> {
387
401
fn try_fill_bytes ( & mut self , dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
388
402
( * * self ) . try_fill_bytes ( dest)
389
403
}
404
+
405
+ fn next ( & mut self ) -> Self :: Item {
406
+ ( * * self ) . next ( )
407
+ }
390
408
}
0 commit comments