Move random utils to another trait.

This commit is contained in:
Bob McWhirter 2021-08-30 09:55:29 -04:00
parent 78f7d1b786
commit 7fa3b27cac
3 changed files with 8 additions and 4 deletions

View file

@ -126,7 +126,9 @@ impl<T: Instance> traits::rng::Rng for Random<T> {
Ok(())
}
}
}
impl<T: Instance> traits::rng::Random for Random<T> {
#[rustfmt::skip]
type NextFuture<'a> where Self: 'a = impl Future<Output=Result<u32, Self::Error>> + 'a;

View file

@ -5,9 +5,9 @@ pub trait Rng {
type Error;
#[rustfmt::skip]
type RngFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
type RngFuture<'a>: Future<Output = Result<(), Self::Error> > + 'a
where
Self: 'a;
Self: 'a;
/// Completely fill the provided buffer with random bytes.
///
@ -15,9 +15,11 @@ pub trait Rng {
/// filling the buffer. Upon completion, the buffer will be completely
/// filled or an error will have been reported.
fn fill_bytes<'a>(&'a mut self, dest: &'a mut [u8]) -> Self::RngFuture<'a>;
}
pub trait Random: Rng {
#[rustfmt::skip]
type NextFuture<'a>: Future<Output = Result<u32, Self::Error>> + 'a
type NextFuture<'a>: Future<Output = Result<u32, <Self as Rng>::Error>> + 'a
where
Self: 'a;

View file

@ -13,7 +13,7 @@ use embassy_stm32::Peripherals;
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
use embassy_stm32::rng::Random;
use embassy::traits::rng::Rng;
use embassy::traits::rng::Random as _;
#[embassy::main]
async fn main(_spawner: Spawner, p: Peripherals) {