Diagram/Graph in doc

Hello!
how to make a diagram / graph in documentation?

For example:

    ///My description 
    ///```markdown
    /// graph TD;
    ///A-->B;
    ///A-->C;
    ///B-->D;
    ///C-->D;
    ///```
    pub fn my_function(){}

You can make a graph in graphviz, then convert it to svg using dot -Tsvg and put the svg directly in your documentation or use something like:

// Macro copied from core/num/mod.rs
macro_rules! doc_comment {
    ($x:expr, $($tt:tt)*) => {
        #[doc = $x]
        $($tt)*
    };
}

doc_comment! {
    concat!("Part before the graph", include_str!("./graph.svg"), "Part after the graph"),
    fn a() {}
}
2 Likes