如何分辨什么“特征"?每个板条箱可用吗? [英] How to tell what "features" are available per crate?

查看:63
本文介绍了如何分辨什么“特征"?每个板条箱可用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种标准方法可以确定给定 crate 可用的功能?

Is there a standard way to determine what features are available for a given crate?

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

I'm trying to read Postgres timezones, and this says to use the crate postgres = "0.17.0-alpha.1" crate's with-time or with-chrono features.

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

When I try this in my 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.

此外,postgres 0.17.0 的 crate 页面 没有提及这些功能,所以我什至不知道他们是否应该得到支持.

Furthermore, the crate page for postgres 0.17.0 says nothing about these features, so I don't even know if they're supposed to be supported or not.

似乎在 docs.rs 上有什么内容?

推荐答案

查看可用功能的唯一保证方法是查看 Cargo.toml 以获取 crate.这通常意味着您需要导航到项目的存储库,找到您感兴趣的版本的正确文件,然后阅读它.

The only guaranteed way to see what features are available is to look at the Cargo.toml for the crate. This generally means that you need to navigate to the project's repository, find the correct file for the version you are interested in, and read it.

您主要查找 [features] 部分,但也查找标记为 optional = true 的任何依赖项,如 可选依赖项算作隐式功能标志.

You are primarily looking for the [features] section, but also for any dependencies that are marked as optional = true, as optional dependencies count as an implicit feature flag.

不幸的是,没有要求 crate 作者提供任何关于每个功能标志的作用的文档.好的 crate 会在一个或多个位置记录其特征标志:

Unfortunately, there's no requirement that the crate author puts any documentation about what each feature flag does. Good crates will document their feature flags in one or more locations:

  • 作为 Cargo.toml 中的注释
  • 他们的自述文件
  • 他们的文档

除了查看 Cargo.toml 之外,上传到 docs.rs 的 crate 还会显示存在哪些功能标志.

In addition to looking at the Cargo.toml, crates uploaded to docs.rs will show what feature flags exist.

crates.io issue #465 建议放置功能列表也在箱子的页面上.

crates.io issue #465 suggests placing the feature list on the crate's page as well.

另见:

对于 postgres crate,我们可以从 crates.io 开始,然后点击存储库"转到存储库.然后我们找到正确的标签(postgres-v0.17.0),然后阅读 货物.toml:

For the postgres crate, we can start at crates.io, then click "repository" to go to the repository. We then find the right tag (postgres-v0.17.0), then read the 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"]

这篇关于如何分辨什么“特征"?每个板条箱可用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆