你如何启用 Rust 的“板条箱功能"? [英] How do you enable a Rust "crate feature"?

查看:74
本文介绍了你如何启用 Rust 的“板条箱功能"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use rand::SmallRng. The documentation says

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

This PRNG is feature-gated: to use, you must enable the crate feature small_rng.

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

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. This is the best I could come up with:

[features]
default = ["small_rng"]

但我明白了:

Feature default 包括 small_rng 既不是依赖项也不是另一个特性

Feature default includes small_rng which is neither a dependency nor another feature

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

Are the docs wrong, or is there something I'm missing?

推荐答案

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

Specify the dependencies in Cargo.toml like so:

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

或者:

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

两者都有效.

这篇关于你如何启用 Rust 的“板条箱功能"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆