首页 > 解决方案 > 如何激活可选依赖项?

问题描述

货物.toml:

[features]
parallel = ["rayon"]

[dependencies.rayon]
version = "1.5"
optional = true

lib.rs:

#[cfg(feature = "parallel")]
pub mod par;

锈分析器:

code is inactive due to #[cfg] directives: feature = "parallel" is disabled

如何启用可选依赖项?

标签: rustrust-cargo

解决方案


您可以将 Rust Analyzer 配置选项设置rust-analyzer.cargo.features为一个数组,其中包含您希望 RA 认为处于活动状态的功能列表。

您还可以设置rust-analyzer.cargo.allFeatures为 true,以启用项目中的所有功能。

设置这些的方法因您使用的 IDE 而异 - 例如,如果使用 VS Code,您可以通过 Rust Analyzer 的“扩展设置”进行设置。

这假设您询问如何激活 Rust Analyzer 中的功能 - 在从 Cargo 构建或运行时激活它们,只需使用该--features选项。

参见:Rust Analyzer 手册


推荐阅读