Is there a way to embed sequence diagrams in rustdoc?

1k views Asked by At

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.

2

There are 2 answers

0
Jean-Marc Volle On

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

0
kmdreko On

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.