有没有一种方法可以将序列图嵌入rustdoc?

时间:2020-10-14 07:14:37

标签: rust rustdoc

正如他们所说,一张图片价值1000字。我想在生成的sequence diagrams中嵌入几个rust documentation。有没有办法做到这一点?拥有embedded image并不能真正起作用,很难维护,它是文档之外的资产,等等。

2 个答案:

答案 0 :(得分:2)

最通用的方法只是在非代码块中使用基于文本的图表。

/// 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 {

}

最终将像这样渲染:

generated docs

这是否可以接受和/或实际取决于您。

答案 1 :(得分:1)

您是否看过: https://docs.rs/crate/mdbook-plantuml/0.3.0

Plantuml是一个非常好的工具,可以使用易于维护的文本来描述序列图。 这是plantuml website的示例:

enter image description here