2

As they say, one picture is worth 1000 words. I'd like to embed several sequence diagrams in my generated rust documentation. Is there a way to do this? Having an embedded image doesn't really work, it is harder to maintain, it is an asset outside of the docs, etc.

Bruce
  • 503
  • 3
  • 13
  • That is exactly why I dislike Markdown/CommonMark as a documentation format - lack of extensibility. – Hauleth Oct 14 '20 at 08:29

2 Answers2

3

The most universal method would just be a text-based diagram in a non-code code block.

/// This module contains structs and functions for communicating to and from
/// the server. It is very important that you understand this diagram so you
/// will appreciate how much work has gone into this. Just look at it! Its
/// beautiful!
/// 
/// ```none
/// +------------+          +------------+
/// |   Client   |          |   Server   |
/// +------------+          +------------+
///       |                        |
///       | request("/")           |
///       +----------------------> |
///       |                        |
///       |             response() |
///       | <----------------------+
///       |                        |
///       |                        |
///       v                        v
/// ```
/// 
/// Appreciating the diagram will give you a +1 to confidence for the rest of
/// the day.
pub mod connection {

}

Will end up rendering like this:

generated docs

Its up to you whether this acceptable and/or practical.

kmdreko
  • 42,554
  • 6
  • 57
  • 106
1

Did you have a look at: https://docs.rs/crate/mdbook-plantuml/0.3.0

Plantuml is a really good tool to describe sequence diagram using easy to maintain text. Here is a sample from plantuml website:

enter image description here

Jean-Marc Volle
  • 3,113
  • 1
  • 16
  • 20