Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include an arbitrary markdown file as a documentation attribute? [duplicate]

Tags:

rust

rustdoc

If the readme Cargo.toml key is set, doc.rs renders the README on the crate's index page. Is there a way to emulate this when running cargo doc locally?

If I add:

#![doc = r###"contents
of
README.md
here
"###]

as a literal, I get the behaviour I'm looking for, but inlining a copy of my whole README.md is pretty inconvenient for making updates.

I tried:

#![doc = include!("README.md")]

but this gives an error:

error: unexpected token: `include`
 --> src/lib.rs:3:10
  |
3 | #![doc = include!("README.md")]
  |          ^^^^^^^
like image 430
Daniel Wagner-Hall Avatar asked Aug 08 '19 22:08

Daniel Wagner-Hall


1 Answers

There is an unstable feature, external-doc, which enables this:

Example usage (nightly-only):

#![feature(external_doc)]

#![doc(include = "../README.md")]
like image 200
Daniel Wagner-Hall Avatar answered Sep 28 '22 07:09

Daniel Wagner-Hall