Skip to content

Commit 8f20839

Browse files
bors[bot]austinbes
andauthored
Merge #56
56: Add nonblocking RNG trait r=therealprof a=austinglaser As discussed in #45, this is a nonblocking variant of an RNG interface. Co-authored-by: Austin Glaser <[email protected]>
2 parents db09d73 + 61877ce commit 8f20839

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## [Unreleased]
99

1010
### Added
11-
11+
- A nonblocking trait for interfacing with random number generation hardware.
1212

1313
### Changed
1414
- The current versions of `InputPin` have been proven. These are `digital::v1::InputPin`

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ pub mod blocking;
689689
pub mod digital;
690690
pub mod fmt;
691691
pub mod prelude;
692+
pub mod rng;
692693
pub mod serial;
693694
pub mod spi;
694695
pub mod timer;

src/prelude.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub use digital::OutputPin as _embedded_hal_digital_OutputPin;
2525
#[cfg(feature = "unproven")]
2626
#[allow(deprecated)]
2727
pub use digital::ToggleableOutputPin as _embedded_hal_digital_ToggleableOutputPin;
28+
#[cfg(feature = "unproven")]
29+
pub use rng::Read as _embedded_hal_rng_Read;
2830
pub use serial::Read as _embedded_hal_serial_Read;
2931
pub use serial::Write as _embedded_hal_serial_Write;
3032
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 implementation or users yet
9+
pub trait Read {
10+
/// An enumeration of RNG errors.
11+
///
12+
/// For infallible implementations, will be `Infallible`
13+
type Error;
14+
15+
/// Get a number of bytes from the RNG.
16+
fn read(&mut self, buf: &mut [u8]) -> nb::Result<usize, Self::Error>;
17+
}

0 commit comments

Comments
 (0)