Extract documentation for the feature flags from comments in Cargo.toml

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
Slint
Slint - The Fast and Easy UI Toolkit
Slint
languagetool-code-comments integrates the LanguageTool API to parse, spell check, and correct the grammar of your code comments!

languagetool-code-comments integrates the LanguageTool API to parse, spell check, and correct the grammar of your code comments! Overview Install MacO

Dustin Blackman 17 Dec 25, 2022
🍅 A command-line tool to get and set values in toml files while preserving comments and formatting

tomato Get, set, and delete values in TOML files while preserving comments and formatting. That's it. That's the feature set. I wrote tomato to satisf

C J Silverio 15 Dec 23, 2022
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

null 294 Dec 23, 2022
Document your crate's feature flags

Document your crate's feature flags This crate provides a macro that extracts documentation comments from Cargo.toml To use this crate, add #![doc = d

SixtyFPS 83 Dec 15, 2022
Toggle parallelism with feature flags!

maybe_parallel_iterator Write your code once. Then toggle between sequential and parallel iterators with a feature flag! let a: Vec<i32> = (0..100).co

Finn Bear 2 May 30, 2022
Find potential unused enabled feature flags and prune them.

Potential unused, enabled feature flag finder and pruner. This cargo tool allows you to find and prune enabled, but, potentially unused feature flags

Timon 118 Jun 29, 2023
Find unused dependencies in Cargo.toml

cargo-udeps Find unused dependencies in Cargo.toml. While compilation of this tool also works on Rust stable, it needs Rust nightly to actually run. I

null 997 Jan 4, 2023
Serde definition of Cargo.toml structure

Deserialize Cargo.toml This is a definition of fields in Cargo.toml files for serde. It allows reading of Cargo.toml data, and serializing it using TO

null 11 Dec 20, 2023
Detect and remove unused dependencies from Cargo.toml

Cargo Shear ✂️ ?? Detect and remove unused dependencies from Cargo.toml in Rust projects. Installation cargo binstall cargo-shear # OR cargo install c

Boshen 49 Jul 25, 2024
Cargo command to create the README.md from your crate's documentation

Cargo rdme Cargo command to create your README from your crate’s documentation. Installation You can install cargo rdme with cargo by running cargo in

Diogo Sousa 42 Dec 24, 2022
A crate implementing POSIX/GNU-style --flags.

pflag is a port of the spf13's popular fork of the Go package by the same name.

null 11 Jul 21, 2022
A rust interval arithmetic library which provides flags that detect domain errors.

intervals-good A Rust interval arithmetic library which provides flags that detect domain errors, supports more functions than any other interval arit

Oliver Flatt 3 Jul 27, 2022
Pulls the C/C++ library linking flags from Conan dependencies

conan2-rs Introduction conan2-rs is a Cargo build script wrapper of the Conan C/C++ package manager (version 2.0 only). It automatically pulls the C/C

Sergey Kvachonok 5 Oct 17, 2023
An interactive scripting language where you can read and modify code comments as if they were regular strings

An interactive scripting language where you can read and modify code comments as if they were regular strings. Add and view text-based visualizations and debugging information inside your source code file.

Sumeet Agarwal 13 Apr 28, 2022
A programming language where comments are the first-class citizen and ASCII art flowcharts are the controls!

regretti ?? A programming language where comments are the first-class citizen and ASCII art flowcharts are the controls! Made for Lang Jam (jam0001) t

Mufeed VH 15 Dec 27, 2022
Dfinity's fungible token standard. Any PRs and comments are welcome,collaborate with us to build this standard

Dfinity's fungible token standard. Any PRs and comments are welcome,collaborate with us to build this standard

Deland Labs 46 Nov 7, 2022
Subsocial full node with Substrate/Polkadot pallets for decentralized communities: blogs, posts, comments, likes, reputation.

Subsocial Node by DappForce Subsocial is a set of Substrate pallets with web UI that allows anyone to launch their own decentralized censorship-resist

DappForce 74 Nov 24, 2022
In this repository you can find modules with code and comments that explain rust syntax and all about Rust lang.

Learn Rust What is this? In this repository you can find modules with code and comments that explain rust syntax and all about Rust lang. This is usef

Domagoj Ratko 5 Nov 5, 2022
📝 Generate your README.md from Rust doc comments

cargo-onedoc ?? Generate README.md from doc comments. Only write your documentation once! This crate provides a Cargo subcommand that can generate Mar

Ross MacArthur 2 Dec 14, 2022
PlandUML and Drawio diagrams in doc comments as PNG or SVG images.

rsdoc This crate provides a procedural macro that transform PlandUML and Drawio diagrams in doc comments as PNG or SVG images. The diagrams in doc com

null 4 Feb 20, 2023