【问题标题】:Feature 'xxx' depends on 'yyy' which is not an optional dependency功能 'xxx' 依赖于 'yyy',它不是可选依赖项
【发布时间】:2019-10-21 11:50:25
【问题描述】:

我收到了这个错误:

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 书中读到的内容,这样做应该意味着默认情况下客户端和服务器具有这些依赖关系,对吧?

【问题讨论】:

  • 只要重读doc.rust-lang.org/cargo/reference/…,我就会明白问题所在。因为我使用了一个工具来自动生成它,所以我不知道为什么会失败,功能仅用于可选编译所以是的@Shepmaster,没有必要在 [features] 下添加强制板条箱。很抱歉,我很确定问题与[功能]有关,这就是为什么我只发布了这个。

标签: rust rust-cargo


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-15
    • 1970-01-01
    • 2021-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-05
    • 1970-01-01
    相关资源
    最近更新 更多