2021-04-26 15:43:19 +02:00
|
|
|
use core::future::Future;
|
|
|
|
|
|
|
|
/// Random-number Generator
|
|
|
|
pub trait Rng {
|
|
|
|
type Error;
|
|
|
|
|
2021-08-27 22:10:01 +02:00
|
|
|
#[rustfmt::skip]
|
2021-08-30 15:55:29 +02:00
|
|
|
type RngFuture<'a>: Future<Output = Result<(), Self::Error> > + 'a
|
2021-04-26 15:43:19 +02:00
|
|
|
where
|
2021-08-30 15:55:29 +02:00
|
|
|
Self: 'a;
|
2021-04-26 15:43:19 +02:00
|
|
|
|
|
|
|
/// Completely fill the provided buffer with random bytes.
|
|
|
|
///
|
|
|
|
/// May result in delays if entropy is exhausted prior to completely
|
|
|
|
/// filling the buffer. Upon completion, the buffer will be completely
|
|
|
|
/// filled or an error will have been reported.
|
2021-05-06 20:33:29 +02:00
|
|
|
fn fill_bytes<'a>(&'a mut self, dest: &'a mut [u8]) -> Self::RngFuture<'a>;
|
2021-08-30 15:55:29 +02:00
|
|
|
}
|
2021-08-27 22:10:01 +02:00
|
|
|
|
2021-08-30 15:55:29 +02:00
|
|
|
pub trait Random: Rng {
|
2021-08-27 22:10:01 +02:00
|
|
|
#[rustfmt::skip]
|
2021-08-30 15:55:29 +02:00
|
|
|
type NextFuture<'a>: Future<Output = Result<u32, <Self as Rng>::Error>> + 'a
|
2021-08-27 22:10:01 +02:00
|
|
|
where
|
|
|
|
Self: 'a;
|
|
|
|
|
|
|
|
fn next<'a>(&'a mut self, range: u32) -> Self::NextFuture<'a>;
|
2021-04-26 15:43:19 +02:00
|
|
|
}
|