Use getrandom as default (for no-std feature)
This commit is contained in:
@@ -25,11 +25,17 @@ Take a look to the conventions established by existing code:
|
|||||||
* Every module should provide a Rust doctest, a brief test embedded with the documentation that explains how to use the procedure implemented.
|
* Every module should provide a Rust doctest, a brief test embedded with the documentation that explains how to use the procedure implemented.
|
||||||
* Every module should provide comprehensive tests at the end, in its `mod tests {}` sub-module. These tests can be flagged or not with configuration flags to allow WebAssembly target.
|
* Every module should provide comprehensive tests at the end, in its `mod tests {}` sub-module. These tests can be flagged or not with configuration flags to allow WebAssembly target.
|
||||||
* Run `cargo doc --no-deps --open` and read the generated documentation in the browser to be sure that your changes reflects in the documentation and new code is documented.
|
* Run `cargo doc --no-deps --open` and read the generated documentation in the browser to be sure that your changes reflects in the documentation and new code is documented.
|
||||||
|
|
||||||
|
#### digging deeper
|
||||||
* a nice overview of the codebase is given by [static analyzer](https://mozilla.github.io/rust-code-analysis/metrics.html):
|
* a nice overview of the codebase is given by [static analyzer](https://mozilla.github.io/rust-code-analysis/metrics.html):
|
||||||
```
|
```
|
||||||
$ cargo install rust-code-analysis-cli
|
$ cargo install rust-code-analysis-cli
|
||||||
|
// print metrics for every module
|
||||||
$ rust-code-analysis-cli -m -O json -o . -p src/ --pr
|
$ rust-code-analysis-cli -m -O json -o . -p src/ --pr
|
||||||
|
// print full AST for a module
|
||||||
|
$ rust-code-analysis-cli -p src/algorithm/neighbour/fastpair.rs --ls 22 --le 213 -d > ast.txt
|
||||||
```
|
```
|
||||||
|
* find more information about what happens in your binary with [`twiggy`](https://rustwasm.github.io/twiggy/install.html). This need a compiled binary so create a brief `main {}` function using `smartcore` and then point `twiggy` to that file.
|
||||||
|
|
||||||
## Issue Report Process
|
## Issue Report Process
|
||||||
|
|
||||||
|
|||||||
@@ -28,3 +28,4 @@ out.svg
|
|||||||
FlameGraph/
|
FlameGraph/
|
||||||
out.stacks
|
out.stacks
|
||||||
*.json
|
*.json
|
||||||
|
*.txt
|
||||||
+9
-11
@@ -16,6 +16,7 @@ exclude = [
|
|||||||
".gitignore",
|
".gitignore",
|
||||||
"smartcore.iml",
|
"smartcore.iml",
|
||||||
"smartcore.svg",
|
"smartcore.svg",
|
||||||
|
"tests/"
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
@@ -25,6 +26,7 @@ ndarray = { version = "0.15", optional = true }
|
|||||||
num-traits = "0.2.12"
|
num-traits = "0.2.12"
|
||||||
num = "0.4"
|
num = "0.4"
|
||||||
rand = { version = "0.8.5", default-features = false, features = ["small_rng"] }
|
rand = { version = "0.8.5", default-features = false, features = ["small_rng"] }
|
||||||
|
getrandom = { version = "*", features = ["js"] }
|
||||||
rand_distr = { version = "0.4", optional = true }
|
rand_distr = { version = "0.4", optional = true }
|
||||||
serde = { version = "1", features = ["derive"], optional = true }
|
serde = { version = "1", features = ["derive"], optional = true }
|
||||||
|
|
||||||
@@ -32,25 +34,21 @@ serde = { version = "1", features = ["derive"], optional = true }
|
|||||||
default = []
|
default = []
|
||||||
serde = ["dep:serde"]
|
serde = ["dep:serde"]
|
||||||
ndarray-bindings = ["dep:ndarray"]
|
ndarray-bindings = ["dep:ndarray"]
|
||||||
datasets = ["dep:rand_distr", "std", "serde"]
|
datasets = ["dep:rand_distr", "std_rand", "serde"]
|
||||||
std = ["rand/std_rng", "rand/std"]
|
std_rand = ["rand/std_rng", "rand/std"]
|
||||||
# wasm32 only
|
|
||||||
js = ["getrandom/js"]
|
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
getrandom = { version = "0.2", optional = true }
|
getrandom = { version = "0.2", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
itertools = "*"
|
|
||||||
criterion = { version = "0.4", default-features = false }
|
|
||||||
serde_json = "1.0"
|
|
||||||
bincode = "1.3.1"
|
|
||||||
|
|
||||||
[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dev-dependencies]
|
[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dev-dependencies]
|
||||||
wasm-bindgen-test = "0.3"
|
wasm-bindgen-test = "0.3"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
itertools = "*"
|
||||||
|
serde_json = "1.0"
|
||||||
|
bincode = "1.3.1"
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
resolver = "2"
|
|
||||||
|
|
||||||
[profile.test]
|
[profile.test]
|
||||||
debug = 1
|
debug = 1
|
||||||
|
|||||||
+6
-1
@@ -1,5 +1,7 @@
|
|||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
pub(crate) use rand::rngs::SmallRng as RngImpl;
|
pub(crate) use rand::rngs::SmallRng as RngImpl;
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
use getrandom;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub(crate) use rand::rngs::StdRng as RngImpl;
|
pub(crate) use rand::rngs::StdRng as RngImpl;
|
||||||
use rand::SeedableRng;
|
use rand::SeedableRng;
|
||||||
@@ -13,7 +15,10 @@ pub(crate) fn get_rng_impl(seed: Option<u64>) -> RngImpl {
|
|||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
RngImpl::seed_from_u64(rand::thread_rng().next_u64())
|
RngImpl::seed_from_u64(rand::thread_rng().next_u64())
|
||||||
} else {
|
} else {
|
||||||
panic!("seed number needed for non-std build");
|
// non-std build, use getrandom
|
||||||
|
let mut buf = [0u8; 64];
|
||||||
|
getrandom::getrandom(&mut buf).unwrap();
|
||||||
|
RngImpl::seed_from_u64(buf[0] as u64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user