首页 > 解决方案 > 功能 'xxx' 依赖于 'yyy',这不是可选依赖项

问题描述

我收到了这个错误:

error: failed to parse manifest at `...\Cargo.toml`

Caused by:
  Feature `client` depends on `rusttls` which is not an optional dependency.
Consider adding `optional = true` to the dependency

如果我添加它,它就会消失optional = true,但出于安全原因,我不希望 rusttls 是可选的。

除了将其设为可选之外,此错误的确切原因和可能的解决方案是什么?

我的 Cargo.toml 有这个:

[features]

default = ["client", "server"]

client = ["serde_json",  "serde-xml-rs", "serde_ignored", "hyper", "hyper-tls", "rusttls", "tokio-core", "url", "uuid", "multipart"]

server = ["serde_json", "serde-xml-rs", "serde_ignored", "hyper", "hyper-tls", "rusttls", "tokio-core", "tokio-proto", "tokio-tls", "regex", "percent-encoding", "url", "uuid", "multipart"]

根据我在 Rust 书中读到的内容,这样做应该意味着默认情况下客户端和服务器具有这些依赖关系,对吧?

标签: rustrust-cargo

解决方案


如果依赖项是可选的,则仅应在功能列表中包含依赖项。如果依赖项不是可选的,则仅将其包含在该[dependencies]部分中。


推荐阅读