Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to embed sequence diagrams in rustdoc?

Tags:

rust

rustdoc

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.

like image 470
Bruce Avatar asked Sep 16 '25 15:09

Bruce


1 Answers

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.

like image 119
kmdreko Avatar answered Sep 19 '25 06:09

kmdreko