@@ -430,12 +430,14 @@ See the links for caveats and examples.
430
430
### Feature documentation and discovery
431
431
432
432
You are encouraged to document which features are available in your package.
433
- Users can look at the ` Cargo.toml ` file, but sometimes it can be hard to track
434
- it down[ ^ crate-source ] . Placing the documentation in the crate root
435
- documentation can be more accessible, for example see the [ regex crate
436
- features] .
437
-
438
- Clearly documenting the features can also set expectations about features
433
+ This can be done by adding [ doc comments] at the top of ` lib.rs ` . As an
434
+ example, see the [ regex crate source] , which when rendered can be viewed on
435
+ [ docs.rs] [ regex-docs-rs ] . If you have other documentation, such as a user
436
+ guide, consider adding the documentation there (for example, see [ serde.rs] ).
437
+ If you have a binary project, consider documenting the features in the README
438
+ or other documentation for the project (for example, see [ sccache] ).
439
+
440
+ Clearly documenting the features can set expectations about features
439
441
considered "unstable" or otherwise shouldn't be used. For example, if there is
440
442
an optional dependency, but you don't want users to explicitly list that
441
443
optional dependency as a feature, exclude it from the documented list.
@@ -450,14 +452,25 @@ control which features are enabled when the documentation is built. See
450
452
> documentation] , where you can see colored boxes which note which features
451
453
> are required to use it.
452
454
453
- [ regex crate features ] : https://docs.rs/regex/1.4.2/regex/#crate-features
454
- [ ^ crate-source ] : The crate page on [ crates.io] has a link to the source
455
- repository if available. Tools like [ ` cargo vendor ` ] or
456
- [ cargo-clone-crate] can be used to download the source and inspect it.
457
-
458
- [ `cargo vendor` ] : ../commands/cargo-vendor.md
459
- [ cargo-clone-crate ] : https://crates.io/crates/cargo-clone-crate
460
- [ docs.rs ] : https://docs.rs/
461
455
[ docs.rs metadata documentation ] : https://docs.rs/about/metadata
456
+ [ docs.rs ] : https://docs.rs/
457
+ [ serde.rs ] : https://serde.rs/feature-flags.html
458
+ [ doc comments ] : ../../rustdoc/how-to-write-documentation.html
459
+ [ regex crate source ] : https://github.com/rust-lang/regex/blob/1.4.2/src/lib.rs#L488-L583
460
+ [ regex-docs-rs ] : https://docs.rs/regex/1.4.2/regex/#crate-features
461
+ [ sccache ] : https://github.com/mozilla/sccache/blob/0.2.13/README.md#build-requirements
462
462
[ `doc_cfg` ] : ../../unstable-book/language-features/doc-cfg.html
463
463
[ `syn` documentation ] : https://docs.rs/syn/1.0.54/syn/#modules
464
+
465
+ #### Discovering features
466
+
467
+ When features are documented in the library API, this can make it easier for
468
+ your users to discover which features are available and what they do. If the
469
+ feature documentation for a package isn't readily available, you can look at
470
+ the ` Cargo.toml ` file, but sometimes it can be hard to track it down. The
471
+ crate page on [ crates.io] has a link to the source repository if available.
472
+ Tools like [ ` cargo vendor ` ] or [ cargo-clone-crate] can be used to download the
473
+ source and inspect it.
474
+
475
+ [ `cargo vendor` ] : ../commands/cargo-vendor.md
476
+ [ cargo-clone-crate ] : https://crates.io/crates/cargo-clone-crate
0 commit comments