Add embassy-std crate with glue to run embassy on std.

This commit is contained in:
Dario Nieuwenhuis
2020-12-28 03:40:28 +01:00
parent 32c67381df
commit 4a7344cb6f
5 changed files with 106 additions and 20 deletions

View File

@ -5,7 +5,7 @@ authors = ["Dario Nieuwenhuis <dirbaio@dirbaio.net>"]
edition = "2018"
[features]
std = ["futures/std", "rand_core"]
std = ["futures/std"]
defmt-trace = []
defmt-debug = []
defmt-info = []
@ -16,9 +16,6 @@ defmt-error = []
defmt = { version = "0.1.3", optional = true }
log = { version = "0.4.11", optional = true }
# std-only
rand_core = { version = "0.5.1", optional = true, features = ["std"] }
cortex-m = "0.6.4"
futures = { version = "0.3.5", default-features = false }
pin-project = { version = "1.0.2", default-features = false }

View File

@ -4,9 +4,6 @@ pub trait Rand {
fn rand(&self, buf: &mut [u8]);
}
#[cfg(feature = "std")]
static mut RAND: Option<&'static dyn Rand> = Some(&if_std::Rand);
#[cfg(not(feature = "std"))]
static mut RAND: Option<&'static dyn Rand> = None;
pub unsafe fn set_rand(rand: &'static dyn Rand) {
@ -16,15 +13,3 @@ pub unsafe fn set_rand(rand: &'static dyn Rand) {
pub fn rand(buf: &mut [u8]) {
unsafe { unwrap!(RAND, "No rand set").rand(buf) }
}
#[cfg(feature = "std")]
mod if_std {
use rand_core::{OsRng, RngCore};
pub(crate) struct Rand;
impl super::Rand for Rand {
fn rand(&self, buf: &mut [u8]) {
OsRng.fill_bytes(buf)
}
}
}