aboutsummaryrefslogtreecommitdiff
path: root/rand/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rand/src/lib.rs')
-rw-r--r--rand/src/lib.rs110
1 files changed, 9 insertions, 101 deletions
diff --git a/rand/src/lib.rs b/rand/src/lib.rs
index d364bd1..ca231b5 100644
--- a/rand/src/lib.rs
+++ b/rand/src/lib.rs
@@ -13,7 +13,7 @@
//! useful types and distributions, and some randomness-related algorithms.
//!
//! # Quick Start
-//!
+//!
//! To get you started quickly, the easiest and highest-level way to get
//! a random value is to use [`random()`]; alternatively you can use
//! [`thread_rng()`]. The [`Rng`] trait provides a useful API on all RNGs, while
@@ -22,7 +22,7 @@
//!
//! ```
//! use rand::prelude::*;
-//!
+//!
//! if rand::random() { // generates a boolean
//! // Try printing a random unicode code point (probably a bad idea)!
//! println!("char: {}", rand::random::<char>());
@@ -36,7 +36,7 @@
//! ```
//!
//! # The Book
-//!
+//!
//! For the user guide and futher documentation, please read
//! [The Rust Rand Book](https://rust-random.github.io/book).
//!
@@ -58,19 +58,14 @@
#![cfg_attr(not(feature="std"), no_std)]
#![cfg_attr(all(feature="alloc", not(feature="std")), feature(alloc))]
#![cfg_attr(all(feature="simd_support", feature="nightly"), feature(stdsimd))]
-#![cfg_attr(feature = "stdweb", recursion_limit="128")]
#[cfg(feature = "std")] extern crate core;
#[cfg(all(feature = "alloc", not(feature="std")))] #[macro_use] extern crate alloc;
#[cfg(feature="simd_support")] extern crate packed_simd;
-#[cfg(all(target_arch="wasm32", not(target_os="emscripten"), feature="stdweb"))]
-#[macro_use]
-extern crate stdweb;
-
-#[cfg(all(target_arch = "wasm32", feature = "wasm-bindgen"))]
-extern crate wasm_bindgen;
+#[cfg(feature = "rand_os")]
+extern crate rand_os;
extern crate rand_core;
extern crate rand_isaac; // only for deprecations
@@ -119,23 +114,7 @@ pub mod seq;
#[cfg(feature="std")] #[doc(hidden)] pub use deprecated::EntropyRng;
#[allow(deprecated)]
-#[cfg(all(feature="std",
- any(target_os = "linux", target_os = "android",
- target_os = "netbsd",
- target_os = "dragonfly",
- target_os = "haiku",
- target_os = "emscripten",
- target_os = "solaris",
- target_os = "cloudabi",
- target_os = "macos", target_os = "ios",
- target_os = "freebsd",
- target_os = "openbsd", target_os = "bitrig",
- target_os = "redox",
- target_os = "fuchsia",
- windows,
- all(target_arch = "wasm32", feature = "stdweb"),
- all(target_arch = "wasm32", feature = "wasm-bindgen"),
-)))]
+#[cfg(feature="rand_os")]
#[doc(hidden)]
pub use deprecated::OsRng;
@@ -152,23 +131,7 @@ pub mod jitter {
pub use rngs::TimerError;
}
#[allow(deprecated)]
-#[cfg(all(feature="std",
- any(target_os = "linux", target_os = "android",
- target_os = "netbsd",
- target_os = "dragonfly",
- target_os = "haiku",
- target_os = "emscripten",
- target_os = "solaris",
- target_os = "cloudabi",
- target_os = "macos", target_os = "ios",
- target_os = "freebsd",
- target_os = "openbsd", target_os = "bitrig",
- target_os = "redox",
- target_os = "fuchsia",
- windows,
- all(target_arch = "wasm32", feature = "stdweb"),
- all(target_arch = "wasm32", feature = "wasm-bindgen"),
-)))]
+#[cfg(feature="rand_os")]
#[doc(hidden)]
pub mod os {
pub use deprecated::OsRng;
@@ -549,13 +512,13 @@ macro_rules! impl_as_byte_slice {
impl_as_byte_slice!(u16);
impl_as_byte_slice!(u32);
impl_as_byte_slice!(u64);
-#[cfg(rust_1_26)] impl_as_byte_slice!(u128);
+#[cfg(all(rustc_1_26, not(target_os = "emscripten")))] impl_as_byte_slice!(u128);
impl_as_byte_slice!(usize);
impl_as_byte_slice!(i8);
impl_as_byte_slice!(i16);
impl_as_byte_slice!(i32);
impl_as_byte_slice!(i64);
-#[cfg(rust_1_26)] impl_as_byte_slice!(i128);
+#[cfg(all(rustc_1_26, not(target_os = "emscripten")))] impl_as_byte_slice!(i128);
impl_as_byte_slice!(isize);
macro_rules! impl_as_byte_slice_arrays {
@@ -712,61 +675,6 @@ pub fn random<T>() -> T where Standard: Distribution<T> {
thread_rng().gen()
}
-// Due to rustwasm/wasm-bindgen#201 this can't be defined in the inner os
-// modules, so hack around it for now and place it at the root.
-#[cfg(all(feature = "wasm-bindgen", target_arch = "wasm32"))]
-#[doc(hidden)]
-#[allow(missing_debug_implementations)]
-pub mod __wbg_shims {
-
- // `extern { type Foo; }` isn't supported on 1.22 syntactically, so use a
- // macro to work around that.
- macro_rules! rust_122_compat {
- ($($t:tt)*) => ($($t)*)
- }
-
- rust_122_compat! {
- extern crate wasm_bindgen;
-
- pub use wasm_bindgen::prelude::*;
-
- #[wasm_bindgen]
- extern "C" {
- pub type Function;
- #[wasm_bindgen(constructor)]
- pub fn new(s: &str) -> Function;
- #[wasm_bindgen(method)]
- pub fn call(this: &Function, self_: &JsValue) -> JsValue;
-
- pub type This;
- #[wasm_bindgen(method, getter, structural, js_name = self)]
- pub fn self_(me: &This) -> JsValue;
- #[wasm_bindgen(method, getter, structural)]
- pub fn crypto(me: &This) -> JsValue;
-
- #[derive(Clone, Debug)]
- pub type BrowserCrypto;
-
- // TODO: these `structural` annotations here ideally wouldn't be here to
- // avoid a JS shim, but for now with feature detection they're
- // unavoidable.
- #[wasm_bindgen(method, js_name = getRandomValues, structural, getter)]
- pub fn get_random_values_fn(me: &BrowserCrypto) -> JsValue;
- #[wasm_bindgen(method, js_name = getRandomValues, structural)]
- pub fn get_random_values(me: &BrowserCrypto, buf: &mut [u8]);
-
- #[wasm_bindgen(js_name = require)]
- pub fn node_require(s: &str) -> NodeCrypto;
-
- #[derive(Clone, Debug)]
- pub type NodeCrypto;
-
- #[wasm_bindgen(method, js_name = randomFillSync, structural)]
- pub fn random_fill_sync(me: &NodeCrypto, buf: &mut [u8]);
- }
- }
-}
-
#[cfg(test)]
mod test {
use rngs::mock::StepRng;