2.1 特性
1分钟内可阅读完
原文链接: https://rust-random.github.io/book/crate-features.html
建议查看 crate 的 Cargo.toml 或 README.md 以了解特性。自 rand v0.9 起,rust-random crate 仅使用显式特性(即所有特性都列在 [features] 下)。
Cargo.toml 的发布版本可在 docs.rs 上查看:
- https://docs.rs/crate/rand/latest/source/Cargo.toml.orig
- https://docs.rs/crate/rand_core/latest/source/Cargo.toml.orig
- https://docs.rs/crate/rand_distr/latest/source/Cargo.toml.orig
- https://docs.rs/crate/chacha20/latest/source/Cargo.toml.orig
- https://docs.rs/crate/rand_xoshiro/latest/source/Cargo.toml.orig
- https://docs.rs/crate/rand_pcg/latest/source/Cargo.toml.orig
通用特性
以下特性在 rand_core、rand、rand_distr 以及部分 RNG crate 中通用:
std:启用依赖std库的功能。除rand_core外默认启用;对于no_std用法,请使用default-features = false。alloc:启用需要分配器的功能(用于no_std)。由std隐含。serde:通过serde(1.0 版)启用序列化。
rand_distr 特性
来自 num_traits 和 libm 的浮点函数用于支持 no_std 环境并确保可重现性。如果更倾向于使用 std 的浮点函数(可能提供更好的精度和性能,但可能产生不同的随机值),可以启用 std_math 特性。(请注意,任何其他依赖 num-traits 的 std 特性(默认启用)的 crate 也会产生相同效果。)