How to include my YAML file to rust-doc?

Hello.

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 
//!```yaml
#[doc = include_str!("../my-file.yml")]
//!```

It is not working.

cargo +1.54.0 doc --open

Error:

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

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

3 Likes

Ok.
Its working:

//! Lorem ipsum 
//!```yaml
#![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.