How to tell what “features” are available per crate?

空扰寡人 提交于 2020-01-23 13:03:49

问题


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

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.

When I try this in my Cargo.toml:

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

I get this error:

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.

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.

It seems like there would be something on docs.rs about it?


回答1:


The only standard 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.

Good crates also document their feature flags either in the README or in their documentation.

You may be interested in crates.io issue #465, which suggests placing the feature list on the page.

See also:

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

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"]


来源:https://stackoverflow.com/questions/59761045/how-to-tell-what-features-are-available-per-crate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!