Update features doc

This commit is contained in:
Diggory Hardy 2019-05-07 09:57:43 +01:00
parent efd3b5c964
commit 1ea01ae80e
2 changed files with 27 additions and 31 deletions

View file

@ -20,18 +20,22 @@ travis-ci = { repository = "rust-random/rand" }
appveyor = { repository = "rust-random/rand" }
[features]
# Meta-features:
default = ["std"] # without "std" rand uses libcore
nightly = ["simd_support"] # enables all features requiring nightly rust
# Optional dependencies:
std = ["rand_core/std", "alloc", "getrandom"]
alloc = ["rand_core/alloc"] # enables Vec and Box support (without std)
i128_support = [] # enables i128 and u128 support
simd_support = ["packed_simd"] # enables SIMD support
serde1 = ["rand_core/serde1", "rand_isaac/serde1", "rand_xorshift/serde1"] # enables serialization for PRNGs
# re-export optional WASM dependencies to avoid breakage:
wasm-bindgen = ["getrandom_package/wasm-bindgen"]
stdweb = ["getrandom_package/stdweb"]
getrandom = ["getrandom_package", "rand_core/getrandom"]
# Configuration:
simd_support = ["packed_simd"] # enables SIMD support
[workspace]
members = [
"rand_core",

View file

@ -84,41 +84,33 @@ pinned version of Rustc if you require compatibility with a specific version.
## Crate Features
Rand is built with the `std` and `getrandom` features enabled by default:
Rand is built with these features enabled by default:
- `std` enables functionality dependent on the `std` lib and implies `alloc`
and `getrandom`
- `getrandom` is an optional crate, providing the code behind `rngs::OsRng`;
the continued existance of this feature is not guaranteed so users are
encouraged to specify `std` instead
- `std` enables functionality dependent on the `std` lib
- `alloc` (implied by `std`) enables functionality requiring an allocator
- `getrandom` (implied by `std`) is an optional dependency providing the code
behind `rngs::OsRng`
The following optional features are available:
Optionally, the following dependencies can be enabled:
- `alloc` can be used instead of `std` to provide `Vec` and `Box`.
- `log` enables some logging via the `log` crate.
- `nightly` enables all unstable features (`simd_support`).
- `serde1` enables serialization for some types, via Serde version 1.
- `simd_support` enables uniform sampling of SIMD types (integers and floats).
- `stdweb` enables support for `OsRng` on `wasm32-unknown-unknown` via `stdweb`
combined with `cargo-web`.
- `wasm-bindgen` enables support for `OsRng` on `wasm32-unknown-unknown` via
[`wasm-bindgen`]
- `log` enables logging via the `log` crate
- `serde1` enables serialization for some types, via Serde version 1
- `stdweb` implies `getrandom/stdweb` to enable
`getrandom` support on `wasm32-unknown-unknown`
- `wasm-bindgen` implies `getrandom/wasm-bindgen` to enable
`getrandom` support on `wasm32-unknown-unknown`
[`wasm-bindgen`]: https://github.com/rustwasm/wasm-bindgen
Additionally, these features configure Rand:
`no_std` mode is activated by setting `default-features = false`; this removes
functionality depending on `std`:
- `thread_rng()`, and `random()` are not available, as they require thread-local
storage and an entropy source.
- Since no external entropy is available, it is not possible to create
generators with fresh seeds using the `FromEntropy` trait (user must provide
a seed).
- Several non-linear distributions distributions are unavailable since `exp`
and `log` functions are not provided in `core`.
- Large parts of the `seq`-uence module are unavailable, unless the `alloc`
feature is used (several APIs and many implementations require `Vec`).
- `nightly` enables all experimental features
- `simd_support` (experimental) enables sampling of SIMD values
(uniformly random SIMD integers and floats)
Rand supports limited functionality in `no_std` mode (enabled via
`default-features = false`). In this case, `OsRng` and `from_entropy` are
unavailable (unless `getrandom` is enabled), large parts of `seq` are
unavailable (unless `alloc` is enabled), and `thread_rng` and `random` are
unavailable.
# License