aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob McWhirter <[email protected]>2021-08-30 09:55:29 -0400
committerBob McWhirter <[email protected]>2021-08-30 09:55:29 -0400
commit7fa3b27cac6f647ae5e11bd04a802027fb96a03c (patch)
tree9180e9045fb68e2307d8a727c4a23b95b4f4b20f
parent78f7d1b786d6b838cf80ddd0199707b0db3dc854 (diff)
Move random utils to another trait.
-rw-r--r--embassy-stm32/src/rng.rs2
-rw-r--r--embassy-traits/src/rng.rs8
-rw-r--r--examples/stm32h7/src/bin/rng.rs2
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<T: Instance> traits::rng::Rng for Random<T> {
126 Ok(()) 126 Ok(())
127 } 127 }
128 } 128 }
129}
129 130
131impl<T: Instance> traits::rng::Random for Random<T> {
130 #[rustfmt::skip] 132 #[rustfmt::skip]
131 type NextFuture<'a> where Self: 'a = impl Future<Output=Result<u32, Self::Error>> + 'a; 133 type NextFuture<'a> where Self: 'a = impl Future<Output=Result<u32, Self::Error>> + 'a;
132 134
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 {
5 type Error; 5 type Error;
6 6
7 #[rustfmt::skip] 7 #[rustfmt::skip]
8 type RngFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a 8 type RngFuture<'a>: Future<Output = Result<(), Self::Error> > + 'a
9 where 9 where
10 Self: 'a; 10 Self: 'a;
11 11
12 /// Completely fill the provided buffer with random bytes. 12 /// Completely fill the provided buffer with random bytes.
13 /// 13 ///
@@ -15,9 +15,11 @@ pub trait Rng {
15 /// filling the buffer. Upon completion, the buffer will be completely 15 /// filling the buffer. Upon completion, the buffer will be completely
16 /// filled or an error will have been reported. 16 /// filled or an error will have been reported.
17 fn fill_bytes<'a>(&'a mut self, dest: &'a mut [u8]) -> Self::RngFuture<'a>; 17 fn fill_bytes<'a>(&'a mut self, dest: &'a mut [u8]) -> Self::RngFuture<'a>;
18}
18 19
20pub trait Random: Rng {
19 #[rustfmt::skip] 21 #[rustfmt::skip]
20 type NextFuture<'a>: Future<Output = Result<u32, Self::Error>> + 'a 22 type NextFuture<'a>: Future<Output = Result<u32, <Self as Rng>::Error>> + 'a
21 where 23 where
22 Self: 'a; 24 Self: 'a;
23 25
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;
13use embedded_hal::digital::v2::OutputPin; 13use embedded_hal::digital::v2::OutputPin;
14use example_common::*; 14use example_common::*;
15use embassy_stm32::rng::Random; 15use embassy_stm32::rng::Random;
16use embassy::traits::rng::Rng; 16use embassy::traits::rng::Random as _;
17 17
18#[embassy::main] 18#[embassy::main]
19async fn main(_spawner: Spawner, p: Peripherals) { 19async fn main(_spawner: Spawner, p: Peripherals) {