Skip to content

Commit

Permalink
rand_os: use run-time failure on unsupported WASM platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Jan 8, 2019
1 parent 42ece4f commit f7bfa1a
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion rand_os/src/lib.rs
Expand Up @@ -330,13 +330,33 @@ mod_use!(
wasm32_stdweb
);

/// Per #678 we use run-time failure where WASM bindings are missing
#[cfg(all(
target_arch = "wasm32",
not(target_os = "emscripten"),
not(feature = "wasm-bindgen"),
not(feature = "stdweb"),
))]
compile_error!("enable either wasm_bindgen or stdweb feature");
mod imp {
use rand_core::{Error, ErrorKind};
use super::OsRngImpl;

#[derive(Clone, Debug)]
pub struct OsRng;

impl OsRngImpl for OsRng {
fn new() -> Result<OsRng, Error> {
Err(Error::new(ErrorKind::Unavailable,
"OsRng: support for wasm32 requires emscripten, stdweb or wasm-bindgen"))
}

fn fill_chunk(&mut self, _dest: &mut [u8]) -> Result<(), Error> {
unimplemented!()
}

fn method_str(&self) -> &'static str { unimplemented!() }
}
}

#[cfg(not(any(
target_os = "android",
Expand Down

0 comments on commit f7bfa1a

Please sign in to comment.