This program generates README.md from documentation comments in lib.rs

⚓ Rust    📅 2026-02-28    👤 surdeus    👁️ 1      

surdeus

I made a program that generates README.md from lib.rs doc comments because I think we can a lot do better than #![doc = include_str!("../README.md")].

Given this lib.rs:

//! This prints all prime numbers, using [`println!`]:
//!
//! ```
//! # fn main() {
//! for i in 2.. {
//!     if is_prime(i) {
//!         println!("{i}");
//!     }
//! }
//! # }
//! ```

Generates this README.md:

This prints all prime numbers, using [`println!`](https://doc.rust-lang.org/stable/std/macro.println.html):

```rust
for i in 2.. {
    if is_prime(i) {
        println!("{i}");
    }
}
```

Features

  • Resolves intra-doc links to the docs.rs url:
before after
[`println!`] [`println!`](https://doc.rust-lang.org/stable/std/macro.println.html)

  • Adds rust language to code blocks:
before after
```ignore ```rust

  • Expands macros:
before after
#![doc = concat!("pkg = '", env!("CARGO_PKG_VERSION"), "'")] pkg = '0.4.2'

  • and more!

1 post - 1 participant

Read full topic

🏷️ Rust_feed