如何启用Rust的“crate feature”?

smdncfj3  于 2023-08-05  发布在  其他
关注(0)|答案(2)|浏览(161)

我想使用rand::SmallRng。文件上说
此PRNG为功能门控:要使用,你必须启用crate特性small_rng
我一直在搜索,不知道如何启用“板条箱功能”。这个短语甚至没有在Rust文档的任何地方使用。这是我能想到的最好的:

  1. [features]
  2. default = ["small_rng"]

字符串
但我得到:
特性default包括既不是依赖项也不是其他特性的small_rng
是医生错了还是我漏掉了什么

oknwwptz

oknwwptz1#

在Cargo.toml中指定依赖项,如下所示:

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

字符串
或者:

  1. [dependencies.rand]
  2. version = "0.7.2"
  3. features = ["small_rng"]


两个都行。

x8goxv8g

x8goxv8g2#

添加可使用的功能。即使您最初添加了crate并希望稍后添加一个功能,也可以使用此方法

  1. cargo add rand -F small_rng

字符串

相关问题