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

Crates uploaded to crates.io (and thus to docs.rs) will show what feature flags exist. crates.io issue #465 suggests placing the feature list on the crate’s page as well.

Beyond that, 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.

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.

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:

  • As comments in Cargo.toml
  • Their README
  • Their documentation

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

Leave a Comment