Including md file for rustdoc around a struct

I tried to do this, but rustdoc renders it as text.

    /// ```markdown
    ///
    /// #![doc = include_str!("./error_codes.md")]
    /// ```
    /// #![doc = include_str!("../README.md")]
    /// 
    #[derive(serde::Deserialize, Debug)]
    pub struct Error {}

Try removing the leading /// and make your include_str! calls inner attributes by removing the ! after the #:

    /// ```markdown
    ///
    #[doc = include_str!("./error_codes.md")]
    /// ```
    #[doc = include_str!("../README.md")]
    /// 
    #[derive(serde::Deserialize, Debug)]
    pub struct Error {}

Read more about the #[doc] attribute here:

https://doc.rust-lang.org/rustdoc/write-documentation/the-doc-attribute.html

The most basic function of #[doc] is to handle the actual documentation text. That is, /// is syntax sugar for #[doc]. This means that these two are the same:

/// This is a doc comment.
#[doc = r" This is a doc comment."]
3 Likes