1 unstable release
new 0.1.0 | Apr 21, 2025 |
---|
#86 in #comments
8KB
93 lines
no-incode-comments
A Rust procedural macro that allows you to keep documentation for your code in external Markdown files instead of inline doc comments.
Purpose
This library solves the problem of maintaining documentation alongside your code by:
- Letting you write documentation in proper Markdown files
- Linking those files to your code through a simple attribute macro
- Automatically importing the documentation at compile time
This approach has several benefits:
- Better organization of documentation
- Support for rich Markdown features
- Easier maintenance of extensive documentation
- Improved separation of concerns
Installation
Add this to your Cargo.toml
:
[dependencies]
no-incode-comments = "0.1.0"
Usage
- Create a Markdown file for your documentation (e.g.,
docs/my_function.md
):
# MyFunction
This is documentation for my_function.
It will be rendered as the doc comment for the function.
# AnotherSection
This section won't be included since we're only importing the "MyFunction" section.
- Use the
external_doc
macro to import the documentation:
use no_incode_comments::external_doc;
#[external_doc(path = "docs/my_function.md", key = "MyFunction")]
pub fn my_function() {
// Function implementation
}
The path
parameter specifies the Markdown file location, and the key
parameter indicates which section (by heading) to import.
How It Works
The procedural macro:
- Reads the specified Markdown file
- Parses it to extract the section with the matching header (key)
- Converts that section into Rust doc comments (
///
) - Applies those comments to your function
Example
See the sample code in main.rs
and the corresponding documentation in docs/sample_file.md
.
License
This project is available under the MIT License.
Dependencies
~205–640KB
~15K SLoC