gpt4 book ai didi

rust - 如何分辨每个 crate 可使用哪些 "features"?

转载 作者:行者123 更新时间:2023-12-03 14:39:40 26 4
gpt4 key购买 nike

有没有一种标准的方法来确定给定 crate 可以使用哪些功能?

我正在尝试阅读Postgres时区,this说要使用 crate postgres = "0.17.0-alpha.1"条板箱的with-timewith-chrono功能。

当我在Cargo.toml中尝试此操作时:

[dependencies]
postgres = { version = "0.17.0-alpha.1", features = ["with-time"] }

我收到此错误:

error: failed to select a version for `postgres`.
... required by package `mypackage v0.1.0 (/Users/me/repos/mypackage)`
versions that meet the requirements `^0.17.0-alpha.1` are: 0.17.0, 0.17.0-alpha.2, 0.17.0-alpha.1

the package `mypackage` depends on `postgres`, with features: `with-time` but `postgres` does not have these features.

此外, crate page for postgres 0.17.0并没有说明这些功能,因此我什至不知道是否应该支持它们。

好像会有一些 on docs.rs吗?

最佳答案

查看可用功能的唯一标准方法是查看 crate 的Cargo.toml。通常,这意味着您需要导航到项目的存储库,找到您感兴趣的版本的正确文件,然后阅读它。
您主要是在寻找[features]部分,也正在寻找被标记为optional = trueoptional dependencies count as an implicit feature flag的所有依赖项。
优质包装箱还可以在自述文件或文档中记录其功能标志。
您可能对crates.io issue #465感兴趣,它建议将功能列表放置在页面上。
也可以看看:

  • How do you enable a Rust "crate feature"?

  • 对于postgres crate ,我们可以 start at crates.io,然后单击“存储库”转到 the repository。然后,我们找到正确的标签( postgres-v0.17.0 ),然后阅读 Cargo.toml:
    [features]
    with-bit-vec-0_6 = ["tokio-postgres/with-bit-vec-0_6"]
    with-chrono-0_4 = ["tokio-postgres/with-chrono-0_4"]
    with-eui48-0_4 = ["tokio-postgres/with-eui48-0_4"]
    with-geo-types-0_4 = ["tokio-postgres/with-geo-types-0_4"]
    with-serde_json-1 = ["tokio-postgres/with-serde_json-1"]
    with-uuid-0_8 = ["tokio-postgres/with-uuid-0_8"]

    关于rust - 如何分辨每个 crate 可使用哪些 "features"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59761045/

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