From 97ee245bdad956684f04d98d4c0f84ce9fd6fde6 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 10 Jun 2022 14:23:20 +0200 Subject: [PATCH 1/3] Make default example compatible with cargo check --- README.md | 7 +++++-- lib.rs | 9 ++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4e9dd0c..7e915db 100644 --- a/README.md +++ b/README.md @@ -5,15 +5,18 @@ This crate provides a macro that extracts documentation comments from Cargo.toml -To use this crate, add `#![doc = document_features::document_features!()]` in your crate documentation. +To use this crate, add `#![cfg_attr(feature = "document-features", doc = document_features::document_features!())]` in your crate documentation. The `document_features!()` macro reads your `Cargo.toml` file, extracts feature comments and generates a markdown string for your documentation. Use `## ` and `#! ` comments in your Cargo.toml to document features, for example: ```toml +[package.metadata.docs.rs] +all-features = true # ensures that `document-features` is enabled when building docs + [dependencies] -document-features = "0.1" +document-features = { version = "0.2", optional = true } ## ... [features] diff --git a/lib.rs b/lib.rs index f9e03ae..ef65594 100644 --- a/lib.rs +++ b/lib.rs @@ -6,7 +6,7 @@ Document your crate's feature flags. This crates provides a macro that extracts "documentation" comments from Cargo.toml -To use this crate, add `#![doc = document_features::document_features!()]` in your crate documentation. +To use this crate, add `#![cfg_attr(feature = "document-features", doc = document_features::document_features!())]` in your crate documentation. The `document_features!()` macro reads your `Cargo.toml` file, extracts feature comments and generates a markdown string for your documentation. @@ -16,7 +16,7 @@ Basic example: //! Normal crate documentation goes here. //! //! ## Feature flags -#![doc = document_features::document_features!()] +#![cfg_attr(feature = "document-features", doc = document_features::document_features!())] // rest of the crate goes here. ``` @@ -46,7 +46,10 @@ in where they occur. Use them to group features, for example. #![doc = self_test!(/** [package] name = "..." -## ... +# ... + +[package.metadata.docs.rs] +all-features = true # ensures that `document-features` is enabled when building docs [features] default = ["foo"] From ba776da1e811a7d4bd58c3304ddebf08f5d1f9e8 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 15 Sep 2022 12:35:41 +0200 Subject: [PATCH 2/3] add a hash --- lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.rs b/lib.rs index 6af8a30..bca147b 100644 --- a/lib.rs +++ b/lib.rs @@ -46,7 +46,7 @@ in where they occur. Use them to group features, for example. #![doc = self_test!(/** [package] name = "..." -# ... +## ... [package.metadata.docs.rs] all-features = true # ensures that `document-features` is enabled when building docs From 40ec6a576a89233f4b4a8160c3aa217fb921730a Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 15 Sep 2022 12:36:34 +0200 Subject: [PATCH 3/3] just enable document-features --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7e915db..f0b1eab 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Use `## ` and `#! ` comments in your Cargo.toml to document features, for exampl ```toml [package.metadata.docs.rs] -all-features = true # ensures that `document-features` is enabled when building docs +features = ["document-features"] # ensures that `document-features` is enabled when building docs [dependencies] document-features = { version = "0.2", optional = true }