Summary

This RFC describes a new key under features in Cargo.toml for documentation. This will allow Cargo to display this information to the user and provide a way for rustdoc to eventually render this data (how this is rendered is outside the scope of this RFC).

Example:

[features.serde]
enables = []
doc = "enable support for serialization and deserialization via serde"

Please see the parent meta RFC for background information: feature-metadata.

Motivation

Cargo features have become extremely widely used, with many crates having at least some level of configuration and larger crates winding up with tens of gates. Despite being a first class component of crate structure, they suffer from a documentation problem: users need to maintain documentation separate from feature definition, typically a manually-created table within API docs.

This RFC proposes adding feature documentation to Cargo.toml, which will allow for keeping feature definitions and documentation together.

Guide-level explanation

A new doc key will be allowed within a feature’s table. This key provides a markdown docstring describing the feature. The first paragraph will be treated as a summary, and should be suitable to display standalone without the rest of the description.

Don’t include the name of the feature in the summary; tools will typically already display this documentation alongside the name of the feature.

[features]
# Feature without documentation
foo = []

# Short documentation comment
bar = { enables = ["foo"], doc = "simple docstring here"}

# Tables are preferred for longer descriptions
[features.corge]
enables = ["bar", "baz"]
doc = """
The first paragraph is a short summary, which might be displayed standalone.
This could be a longer description of this feature
"""

See feature-metadata for information about enables.

Reference-level explanation

The new doc key accepts markdown-flavored text, and should be thought of as the equivalent to a #[doc(...)] attribute. Like doc comments, the first paragraph should be treated as a summary. Intra-doc link support is not included in this RFC, so they should not be used.

There is nothing in this RFC that cargo must do with this action, since it is mainly intended for the consumption of rustdoc or docs.rs. However, it can be used for general diagnostic information such as during cargo add or a possible cargo info command. A sample application with cargo add:

crab@rust foobar % cargo add regex
    Updating crates.io index
      Adding regex v1.7.3 to dependencies.
             Features:
             + perf             Enables all performance related features
             + perf-dfa         Enables the use of a lazy DFA for matching
             + perf-inline      Enables the use of aggressive inlining inside
                                match routines
             + perf-literal     Enables the use of literal optimizations for
                                speeding up matches
             + std              When enabled, this will cause regex to use the
                                standard library
             + unicode          Enables all Unicode features

    Updating crates.io index

(features like aho-corasick, memchr, or use_std would likely be public = false since they aren’t listed on the crate landing page)

Any tools that want the information in doc will require access to the manifest. Adding this information to the index was decided against due to concerns about bloat, but this is further discussed in future possibilities.

Drawbacks

Rationale and alternatives

Prior art

Unresolved questions

Future possibilities