gpt4 book ai didi

rust - 如何为 Cargo 中的子依赖项指定功能?

转载 作者:行者123 更新时间:2023-12-03 11:25:17 26 4
gpt4 key购买 nike

我正在开发一个使用 reqwest 和 self_update 的 CLI 应用程序。 self_update 也使用 reqwest。我希望我的应用程序使用 ruSTLs 而不是引入 openssl 依赖项。 Cargo.toml 允许 choosing features依赖项:

[dependencies.reqwest]
version = "0.10"
default-features = false
features = ["rustls-tls", "json", "blocking"]

如果子依赖项有效,那就太酷了:
[dependencies.self_update.reqwest]
version = "0.10"
default-features = false
features = ["rustls-tls", "json", "blocking"]

我也看了 replace section ,但只有这样的东西才能在我分支代码的地方工作:
"reqwest:0.10.1" = { branch = "rustls", git = "https://github.com/ctaggart/reqwest" }

但我想要的是默认功能和支持的功能:
"reqwest:0.10.1" = { tag="v0.10.1", git = "https://github.com/seanmonstar/reqwest", default-features = false, features = ["rustls-tls", "json", "blocking"] }

如何使用 Cargo 配置 Reqwest 或 Tokio 或任何其他高度可配置的非直接依赖项的功能?

最佳答案

我同意你的观点,支持子依赖特性会很棒。
这并不理想,但如果您将子依赖项添加为依赖项,则该功能将起作用。

[dependencies]
...
surf = "2.1.0" # which depends on http-client, which depends on isahc
...

[dependencies.isahc]
features = ["static-ssl"]
如果您不指定版本,您将收到弃用警告,但至少您不必手动跟踪子依赖版本:
warning: dependency (isahc) specified without providing a local path, Git repository, or version to use. This will be considered an error in future versions

关于rust - 如何为 Cargo 中的子依赖项指定功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59994525/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com