简体   繁体   English

如何启用 Rust “板条箱功能”?

[英]How do you enable a Rust "crate feature"?

I'm trying to userand::SmallRng .我正在尝试使用rand::SmallRng The documentation says文件说

This PRNG is feature-gated : to use, you must enable the crate feature small_rng .此 PRNG 是功能门控:要使用,您必须启用板条箱功能small_rng

I've been searching and can't figure out how to enable "crate features".我一直在搜索,无法弄清楚如何启用“板条箱功能”。 The phrase isn't even used anywhere in the Rust docs. Rust 文档中的任何地方都没有使用该短语。 This is the best I could come up with:这是我能想到的最好的:

[features]
default = ["small_rng"]

But I get:但我得到:

Feature default includes small_rng which is neither a dependency nor another feature功能default包括small_rng ,它既不是依赖项也不是其他功能

Are the docs wrong, or is there something I'm missing?文档是错误的,还是我遗漏了什么?

Specify the dependencies in Cargo.toml like so:在 Cargo.toml 中指定依赖项,如下所示:

[dependencies]
rand = { version = "0.7.2", features = ["small_rng"] }

Alternatively:或者:

[dependencies.rand]
version = "0.7.2"
features = ["small_rng"]

Both work.两者都有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM