Skip to content

Commit f33dc49

Browse files
committed
Add nonblocking RNG trait
1 parent 53cf9ab commit f33dc49

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ extern crate nb;
687687
pub mod blocking;
688688
pub mod digital;
689689
pub mod prelude;
690+
pub mod rng;
690691
pub mod serial;
691692
pub mod spi;
692693
pub mod timer;

src/prelude.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ pub use ::blocking::spi::{
2626
pub use ::digital::OutputPin as _embedded_hal_digital_OutputPin;
2727
#[cfg(feature = "unproven")]
2828
pub use ::digital::InputPin as _embedded_hal_digital_InputPin;
29+
#[cfg(feature = "unproven")]
30+
pub use ::rng::Read as _embedded_hal_rng_Read;
2931
pub use ::serial::Read as _embedded_hal_serial_Read;
3032
pub use ::serial::Write as _embedded_hal_serial_Write;
3133
pub use ::spi::FullDuplex as _embedded_hal_spi_FullDuplex;

src/rng.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! Random Number Generator Interface
2+
3+
#[cfg(feature = "unproven")]
4+
use nb;
5+
6+
/// Nonblocking stream of random bytes.
7+
#[cfg(feature = "unproven")]
8+
// reason: No implementations or users yet
9+
pub trait Read {
10+
/// An enumeration of RNG errors
11+
///
12+
/// May be `!` (`never_type`) for infallible implementations; i.e. software PRNGs
13+
type Error;
14+
15+
/// Get a single byte from the RNG
16+
fn read(&mut self) -> nb::Result<u8, Self::Error>;
17+
}

0 commit comments

Comments
 (0)