Document your crate's feature flags

Overview

Document your crate's feature flags

Crates.io Documentation

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. 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:

[dependencies]
document-features = "0.1"
## ...

[features]
## The foo feature enables the `foo` functions
foo = []
## The bar feature enables the [`bar`] module
bar = []

#! ### Experimental features
#! The following features are experimental

## Activate the fusion reactor
fusion = []

These comments keep the feature definition and documentation next to each other, and they are then rendered into your crate documentation.

Check out the documentation for more details.

Contributions

Contributions are welcome. We accept pull requests and bug reports.

License

MIT OR Apache-2.0

Comments
  • Format features with HTML tags as `rustdoc` does

    Format features with HTML tags as `rustdoc` does

    Hello!

    With this PR I suggest formatting the features as

    <span class="stab portability"><code>feature</code></span>
    

    instead of

    **`feature`**
    

    so that they look the same as the ones automatically generated by rustdoc.

    If you don't like this as default, I can put it behind a feature such as html-style or something...

    opened by FedericoStra 15
  • tests fail when run from published crate with Cargo.toml.orig stripped

    tests fail when run from published crate with Cargo.toml.orig stripped

    The process of publishing a crate appears to naturally strip the comments in Cargo.toml.

    Consequently, when i try to build and run the code in this crate from the published crate, i end up with errors in the self-test.

    The published crate (v0.2.6) has this Cargo.toml:

    # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
    #
    # When uploading crates to the registry Cargo will automatically
    # "normalize" Cargo.toml files for maximal compatibility
    # with all versions of Cargo and also rewrite `path` dependencies
    # to registry (e.g., crates.io) dependencies.
    #
    # If you are reading this file be aware that the original Cargo.toml
    # will likely look very different (and much more reasonable).
    # See Cargo.toml.orig for the original contents.
    
    [package]
    edition = "2018"
    name = "document-features"
    version = "0.2.6"
    authors = ["Slint Developers <[email protected]>"]
    description = "Extract documentation for the feature flags from comments in Cargo.toml"
    homepage = "https://slint-ui.com"
    readme = "README.md"
    keywords = [
        "documentation",
        "features",
        "rustdoc",
        "macro",
    ]
    categories = ["development-tools"]
    license = "MIT OR Apache-2.0"
    repository = "https://github.com/slint-ui/document-features"
    
    [lib]
    path = "lib.rs"
    proc-macro = true
    
    [dependencies.litrs]
    version = "0.2.3"
    default-features = false
    
    [features]
    default = []
    self-test = []
    

    This of course results in:

    error: Could not find documented features in Cargo.toml
     --> tests/self-doc.rs:3:5
      |
    3 |     document_features::document_features!();
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
      = note: this error originates in the macro `document_features::document_features` (in Nightly builds, run with -Z macro-backtrace for more info)
    

    This is a concern for me because i'm trying to package the document-features crate in debian, and the debian rust team is currently packaging based on the published crates.

    opened by dkg 6
  • `error: Parse error while parsing line: [`

    `error: Parse error while parsing line: [`

    Hi :wave:

    I tried to add document-features to my project https://github.com/viridIT/vSMTP/compare/develop...doc/feature but I have this error : I believe this is a bug in the parser :bug:

    error: Parse error while parsing line: [
      --> src/vsmtp/vsmtp-core/src/lib.rs:21:10
       |
    21 | #![doc = document_features::document_features!()]
       |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = note: this error originates in the macro `document_features::document_features` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    error: Compilation failed, aborting rustdoc
    
    error: could not document `vsmtp`
    
    Caused by:
      process didn't exit successfully: `rustdoc [...]
    
    opened by Mathieu-Lala 5
  • Indent paragraphed comments under the resp. bullet point for a feature

    Indent paragraphed comments under the resp. bullet point for a feature

    [features]
    default = []
    ## the `spline_inverse()` code will check if the knot vector is
    ## monotonic in *debug* builds.
    ##
    ## ⚠️ This only works when using a *nightly* toolchain.
    unstable = []
    

    Expected MD output:

    • unstable — the spline_inverse() code will check if the knot vector is monotonic in debug builds.

      ⚠️ This only works when using a nightly toolchain.

    Actual MD output:

    • unstable — the spline_inverse() code will check if the knot vector is monotonic in debug builds.

    ⚠️ This only works when using a nightly toolchain.

    opened by virtualritz 3
  • Fix parsing of string literal in proc macro argument

    Fix parsing of string literal in proc macro argument

    From the commit message:

    Commit 056b0b7d09a4ed49e50182df216361397656425c removed the dependency syn.

    In doing so it introduced a bug where the string literal passed to document_features!(feature_label = "...") is not parsed anymore and therefore in the generated Markdown we insert a representation of the string literal as it appears in the source code instead of its content.

    For instance, with the call document_features!(feature_label = r#"foo\"#) we insert in the Markdown the text r#"foo\"# instead of foo\.

    opened by FedericoStra 2
  • document-feature fails with multi-line `default` feature entry

    document-feature fails with multi-line `default` feature entry

    if the entry for the default feature spans multiple lines trying to run cargo doc will return an error:

    error: Parse error while parsing dependency default 
     --> src/main.rs:1:10
      |
    1 | #![doc = document_features::document_features!()]
      |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
      = note: this error originates in the macro `document_features::document_features` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    error: Compilation failed, aborting rustdoc
    

    minimal Cargo.toml & main.rs required for this behaviour:

    [package]
    name = "dt"
    version = "0.1.0"
    edition = "2021"
    
    [features]
    default = [
        "foo"
    ]
    
    ## Doc commment for this feature
    foo = []
    
    [dependencies]
    document-features = "0.2.1"
    
    #![doc = document_features::document_features!()]
    
    fn main() {
        println!("Hello, world!");
    }
    

    if the Cargo.toml is instead changed to the following (default put into a single line), everything works:

    [package]
    name = "dt"
    version = "0.1.0"
    edition = "2021"
    
    [features]
    default = [ "foo" ]
    
    ## Doc commment for this feature
    foo = []
    
    [dependencies]
    document-features = "0.2.1"
    
    opened by dequbed 2
  • Docs suggests `document-features` as an optional feature

    Docs suggests `document-features` as an optional feature

    Hi, and thanks for a great crate!

    The docs suggests adding this to your Cargo.toml:

    ## Enable this when building the docs
    document-features = { version = "0.2", optional = true }
    

    The problem with this is that it breaks cargo check:

    7 | #![doc = document_features::document_features!()]
      |          ^^^^^^^^^^^^^^^^^ use of undeclared crate or module `document_features`
    

    I would suggest updating the docs to instead just have

    document-features = "0.2"
    

    unless there is some way to get around the cargo check issue that I'm not aware of

    opened by emilk 2
  • fix issue with calling `get_balanced` in the wrong table

    fix issue with calling `get_balanced` in the wrong table

    This fixes an issue where get_balanced would be called in a table that isn't [features] or a dependency table.

    To reproduce place below in a Cargo.toml above [features] and try building the docs

    [package.metadata.release]
    pre-release-replacements = [
      {test="## "},
    ]
    

    close #10

    opened by Muscraft 1
  • 0.2.2 breaks my builds

    0.2.2 breaks my builds

    My Cargo.toml is breaking on upgrade to 0.2.2

    error: Parse error while parsing dependency pre-release-replacements : unbalanced source
      --> src/lib.rs:38:50
       |
    38 | #![cfg_attr(feature = "document-features", doc = document_features::document_features!())]
       |                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = note: this error originates in the macro `document_features::document_features` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    opened by epage 1
  • Add license text of both licenses

    Add license text of both licenses

    Make LICENSE.txt a symlink to MIT, so that github will stay happy. It would be so nice if github actually understood SPDX expressions.

    Let me be the annoying license guy again:-/

    opened by hunger 1
  • Support raw string literals and make sure there is nothing after the format string

    Support raw string literals and make sure there is nothing after the format string

    This is a quick follow-up to #12.

    • It adds support for r##"..."## format strings.
    • It makes sure there aren't any other tokens left after the format string.
    opened by FedericoStra 0
  • Recommend having `document-features` as an optional dependency

    Recommend having `document-features` as an optional dependency

    Closes https://github.com/slint-ui/document-features/issues/7

    There are two ways to successfully use document-features. One is to to have it as a mandatory dependency:

    document-features = "0.2" + #![doc = document_features::document_features!()]

    However, this adds a dependency that is only needed when building docs, which is unnecessary. The other way is to have it optional:

    [package.metadata.docs.rs]
    all-features = true
    
    [dependencies]
    document-features = { version = "0.2", optional = true }
    
    #![cfg_attr(feature = "document-features", doc = document_features::document_features!())]
    

    This is more verbose, but means the document-features doesn't become a build dependency, which is great.

    Unfortunately, the old docs had a mix with document-features = { version = "0.2", optional = true } + #![doc = document_features::document_features!()] which fails when you do cargo check.


    In this PR I suggest we always use the more verbose (but in my opinion better) way: the optional dependency.

    opened by emilk 4
  • Consider a shorter alias for the macro name

    Consider a shorter alias for the macro name

    Because #![doc = document_features::document_features!()] is quite long and unnecessary repeats itself.

    I think it'll be better to have something like document_features::get!(), extract, etc.

    opened by pravic 1
Releases(v0.2.7)
Owner
SixtyFPS
SixtyFPS
SixtyFPS
Autorebase automatically rebases all of your feature branches onto master.

Autorebase automatically rebases all of your feature branches onto master. If conflicts are found it will rebase to the last commit that doesn't cause conflicts. By default, branches with an upstream are excluded. You don't need to switch to any branch, the only limitation is that a branch that is checked out and not clean will not be rebased (though I may add that in future).

Tim 66 Nov 26, 2022
Temp repo to document problems with workers-rs

This is a temporarily repo to share some worker-rs code that is giving me problems. See also: https://github.com/cloudflare/workers-rs/issues/94 Versi

Andrew Chin 0 Dec 6, 2021
A simple, yet feature-filled wrapper around the coqui-stt C API

A simple, yet feature-filled wrapper around the coqui-stt C API

0/0 56 Jan 3, 2023
Macros to make writing proc-macro crates easy

proc-easy Macros to make writing proc-macro crates easy. This crate provides mainly macros and supporting types and traits to reduce amount of boilerp

Zakarum 7 Jan 1, 2023
The simplest way to de-Google your life and business: Inbox, Calendar, Files, Contacts & much more

Bloom The all-in-one private workspace Try it for free! You no longer trust tech monopolies with your data? You are done with your privacy invaded by

Sylvain Kerkour 1.6k Dec 26, 2022
EmPOWer your commits with Rust!

git-power-rs What is this? Make your git tree into a blockchain! Inspired by this project, I noticed that there was a call to Rewrite it in Rust™, so

Michael Krasnitski 20 Nov 9, 2022
Play Onitama in your browser, compete with friends or lose to a bot

Play Onitama in your browser, compete with friends or lose to a bot

Jack Adamson 52 Nov 12, 2022
Tells you how many years you need to wait until your subatomic xeon crystal synchronizer has doubled in plasma inversion efficiency on the Goldberg-Moleman scale or whatever.

about Tells you how many years you need to wait until your subatomic xeon crystal synchronizer has doubled in plasma inversion efficiency on the Goldb

null 2 Dec 3, 2021
Common processing blocks used with your Runes.

Common Processing Blocks (API Docs) Processing blocks built by Hammer of the Gods that you can use with your Runes. License This project is licensed u

Hammer of the Gods 9 Jul 21, 2022
A stupid macro that compiles and executes Rust and spits the output directly into your Rust code

inline-rust This is a stupid macro inspired by inline-python that compiles and executes Rust and spits the output directly into your Rust code. There

William 19 Nov 29, 2022
A GitHub Action to automatically build and deploy your mdbook project.

?? deploy-mdbook The deploy-mdbook action allows you to easily build and deploy your mdBook project to GitHub Pages. See action.yml for configuration

null 27 Oct 24, 2022
Telegram bot to fetch images from Terceira Ponte and Rodosol into your Telegram chat.

rodosol-telegram-bot Add this bot to your contacts list This bot is a quick scraper that gets the pictures from the rodosol "De olho na via" feature a

Armando Magalhães 1 Jan 9, 2022
Paru is your standard pacman wrapping AUR helper with lots of features and minimal interaction.

Paru Feature packed AUR helper Description Paru is your standard pacman wrapping AUR helper with lots of features and minimal interaction. Installatio

Lulu 4k Jan 9, 2023
Notifiy when one of Elon Musk's jets flyover your own ADS-B receiver

With inpsiration from twitter/@ElonJet, this app will print notifications when one of Elon Musk's jets fly over your own ADS-B receiver ground station.

Rust ADS-B 6 Dec 19, 2022
A server to continously poll nearly always-on sites to verify that your internet connectivity stays up

Dead Router A server to continously poll nearly always-on sites to verify that your internet connectivity stays up! If one or more of the servers stop

null 0 Feb 5, 2022
Add toast support in your dioxus project

Add toast support in your dioxus project

YuKun Liu 8 Dec 16, 2022
Envwoman is an application, to sync your .env-files across multiple machines

Envwoman is an application, to sync your .env-files across multiple machines. The main goal is to make Envwoman secure and trustworthy, so everything is open-source and the data will never in plain-text on the server. Encryption happens client-sided via aes-gcm.

Mawoka 3 Sep 28, 2022
Automatic wallpaper downloader of posters of your favorite movies and TV shows via TMDb.

Wallpaperflix Automatic wallpaper downloader of posters of your favorite movies and TV shows via TMDb. Prerequisities https://tauri.app/v1/guides/gett

İsmail Karslı 2 Sep 8, 2022
Log your spending in seconds with short text snippets. Powered by Rust, Cloudflare Workers and Svelte.

FastSpend Log your daily spending lightning fast with short text snippets! FastSpend is a tool to log your spending in seconds, powered by a lightning

Phoomparin Mano 24 Sep 13, 2022