如何启用 Rust "crate feature"?
How do you enable a Rust "crate feature"?
我正在尝试使用 rand::SmallRng
。文档说
This PRNG is feature-gated: to use, you must enable the crate feature small_rng
.
我一直在搜索,但无法弄清楚如何启用“板条箱功能”。 Rust 文档中的任何地方甚至都没有使用该短语。这是我能想到的最好的:
[features]
default = ["small_rng"]
但我得到:
Feature default
includes small_rng
which is neither a dependency nor another feature
文档有误,还是我遗漏了什么?
像这样在 Cargo.toml 中指定依赖项:
[dependencies]
rand = { version = "0.7.2", features = ["small_rng"] }
或者:
[dependencies.rand]
version = "0.7.2"
features = ["small_rng"]
两者都有效。
我正在尝试使用 rand::SmallRng
。文档说
This PRNG is feature-gated: to use, you must enable the crate feature
small_rng
.
我一直在搜索,但无法弄清楚如何启用“板条箱功能”。 Rust 文档中的任何地方甚至都没有使用该短语。这是我能想到的最好的:
[features]
default = ["small_rng"]
但我得到:
Feature
default
includessmall_rng
which is neither a dependency nor another feature
文档有误,还是我遗漏了什么?
像这样在 Cargo.toml 中指定依赖项:
[dependencies]
rand = { version = "0.7.2", features = ["small_rng"] }
或者:
[dependencies.rand]
version = "0.7.2"
features = ["small_rng"]
两者都有效。