How to include my YAML file to rust-doc?


I would like to include my YAML file to doc in a rust comment and render him.
It is possible?

Yes, it's now possible in Rust 1.54:

/// ```yaml
#[doc = include_str!("example.yaml")]
/// ```
pub fn example() {}

The path is relative to .rs file the comment is in.

Thanks @kornel for reply... but

//! Lorem ipsum 
#[doc = include_str!("../my-file.yml")]

It is not working.

cargo +1.54.0 doc --open


error[E0753]: expected outer doc comment
  --> src/
10 | //!```
   | ^^^^^^
   = note: inner doc comments like this (starting with `//!` or `/*!`) can only appear before items

#[doc] is for /// comments.
You need #![doc] for //! comments.


Its working:

//! Lorem ipsum 
#![doc = include_str!("../my-file.yml")]
1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.