Skip to content

Add nonblocking RNG trait #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

### Added

- A nonblocking trait for interfacing with random number generation hardware.

### Changed
- The current versions of `InputPin` have been proven. These are `digital::v1::InputPin`
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ pub mod blocking;
pub mod digital;
pub mod fmt;
pub mod prelude;
pub mod rng;
pub mod serial;
pub mod spi;
pub mod timer;
Expand Down
2 changes: 2 additions & 0 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub use digital::OutputPin as _embedded_hal_digital_OutputPin;
#[cfg(feature = "unproven")]
#[allow(deprecated)]
pub use digital::ToggleableOutputPin as _embedded_hal_digital_ToggleableOutputPin;
#[cfg(feature = "unproven")]
pub use rng::Read as _embedded_hal_rng_Read;
pub use serial::Read as _embedded_hal_serial_Read;
pub use serial::Write as _embedded_hal_serial_Write;
pub use spi::FullDuplex as _embedded_hal_spi_FullDuplex;
Expand Down
17 changes: 17 additions & 0 deletions src/rng.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! Random Number Generator Interface

#[cfg(feature = "unproven")]
use nb;

/// Nonblocking stream of random bytes.
#[cfg(feature = "unproven")]
// reason: No implementation or users yet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't there be a cfg gate instead of a comment?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm missing some context here. What does that comment refer to, and what cfg gate should there be instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got #[cfg(feature="unstable")] on the entire rng mod -- I'm happy to put it here as well, or to move this comment to that point. What would you prefer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unstable? ;)

For consistency reasons I'd prefer to have it right in front of the trait definition instead of this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unstable

Whoops. Got it right in the PR, at least =P

I'll put it there

(used the wrong account for the first comment)

pub trait Read {
/// An enumeration of RNG errors.
///
/// For infallible implementations, will be `Infallible`
type Error;

/// Get a number of bytes from the RNG.
fn read(&mut self, buf: &mut [u8]) -> nb::Result<usize, Self::Error>;
}