Skip to content

Commit 5ac8deb

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

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@
679679
#![deny(missing_docs)]
680680
#![deny(warnings)]
681681
#![feature(never_type)]
682+
#![feature(unsize)]
682683
#![no_std]
683684

684685
#[macro_use]
@@ -687,6 +688,8 @@ extern crate nb;
687688
pub mod blocking;
688689
pub mod digital;
689690
pub mod prelude;
691+
#[cfg(feature = "unproven")]
692+
pub mod rng;
690693
pub mod serial;
691694
pub mod spi;
692695
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! Random Number Generator Interface
2+
3+
use nb;
4+
5+
use core::marker::Unsize;
6+
7+
/// Nonblocking stream of random bytes.
8+
// reason: No implementations or users yet
9+
pub trait Read {
10+
/// Format of returned data
11+
type Bytes: Unsize<[u8]>;
12+
13+
/// An enumeration of RNG errors
14+
///
15+
/// May be `!` (`never_type`) for infallible implementations; i.e. software PRNGs
16+
type Error;
17+
18+
/// Get a single byte from the RNG
19+
fn read(&mut self) -> nb::Result<Self::Bytes, Self::Error>;
20+
}

0 commit comments

Comments
 (0)