From 7fa3b27cac6f647ae5e11bd04a802027fb96a03c Mon Sep 17 00:00:00 2001 From: Bob McWhirter Date: Mon, 30 Aug 2021 09:55:29 -0400 Subject: [PATCH] Move random utils to another trait. --- embassy-stm32/src/rng.rs | 2 ++ embassy-traits/src/rng.rs | 8 +++++--- examples/stm32h7/src/bin/rng.rs | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/embassy-stm32/src/rng.rs b/embassy-stm32/src/rng.rs index e94c813de..305e26771 100644 --- a/embassy-stm32/src/rng.rs +++ b/embassy-stm32/src/rng.rs @@ -126,7 +126,9 @@ impl traits::rng::Rng for Random { Ok(()) } } +} +impl traits::rng::Random for Random { #[rustfmt::skip] type NextFuture<'a> where Self: 'a = impl Future> + 'a; diff --git a/embassy-traits/src/rng.rs b/embassy-traits/src/rng.rs index 320d9afc2..181faa515 100644 --- a/embassy-traits/src/rng.rs +++ b/embassy-traits/src/rng.rs @@ -5,9 +5,9 @@ pub trait Rng { type Error; #[rustfmt::skip] - type RngFuture<'a>: Future> + 'a + type RngFuture<'a>: Future > + '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> + 'a + type NextFuture<'a>: Future::Error>> + 'a where Self: 'a; diff --git a/examples/stm32h7/src/bin/rng.rs b/examples/stm32h7/src/bin/rng.rs index 48aad26b1..f779b2f69 100644 --- a/examples/stm32h7/src/bin/rng.rs +++ b/examples/stm32h7/src/bin/rng.rs @@ -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) {