【问题标题】:How do you enable a Rust "crate feature"?你如何启用 Rust 的“板条箱功能”?
【发布时间】:2019-10-21 05:24:48
【问题描述】:

我正在尝试使用rand::SmallRng。文档说

此 PRNG 是功能门控:要使用,您必须启用 crate 功能 small_rng

我一直在搜索,但不知道如何启用“板条箱功能”。这个短语甚至在 Rust 文档中的任何地方都没有使用。这是我能想到的最好的:

[features]
default = ["small_rng"]

但我明白了:

功能default 包括small_rng,它既不是依赖项也不是其他功能

是文档有误,还是我遗漏了什么?

【问题讨论】:

    标签: rust rust-cargo


    【解决方案1】:

    像这样在 Cargo.toml 中指定依赖项:

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

    或者:

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

    两者都有效。

    【讨论】:

      猜你喜欢
      • 2021-02-27
      • 2020-12-26
      • 2020-04-01
      • 2020-09-29
      • 2021-01-08
      • 1970-01-01
      • 1970-01-01
      • 2023-01-20
      • 2022-01-20
      相关资源
      最近更新 更多