#proc-macro #docs #rustdoc #mermaid #diagram


A demo crate for aquamarine -- the mermaid.js integration for rustdoc

15 releases

0.3.1 Apr 17, 2023
0.3.0 Feb 16, 2023
0.2.2 Feb 2, 2023
0.1.12 Aug 17, 2022
0.1.6 Jan 28, 2021

#69 in Procedural macros

Download history 17/week @ 2023-08-14 1/week @ 2023-08-21 34/week @ 2023-08-28 18/week @ 2023-09-04 1/week @ 2023-09-11 1/week @ 2023-09-18 4/week @ 2023-09-25 3/week @ 2023-10-02 1/week @ 2023-10-09 2/week @ 2023-10-23 27/week @ 2023-10-30 20/week @ 2023-11-13 17/week @ 2023-11-20 70/week @ 2023-11-27

108 downloads per month

MIT license

30K SLoC

JavaScript 29K SLoC // 0.0% comments TypeScript 67 SLoC // 0.5% comments Rust 58 SLoC


GitHub crates.io docs.rs

Compiler support: this crate requires rustc 1.38.0 or newer

Aquamarine is a procedural macro extension for rustdoc, that aims to improve the visual component of Rust documentation through use of the mermaid.js diagrams.

#[aquamarine] macro works through embedding the mermaid.js into the generated rustdoc HTML page, modifying the doc comment attributes.

To inline a diagram into the documentation, use the mermaid snippet in a doc-string:

#[cfg_attr(doc, aquamarine::aquamarine)]
/// ```mermaid
/// graph LR
///     s([Source]) --> a[[aquamarine]]
///     r[[rustdoc]] --> f([Docs w/ Mermaid!])
///     subgraph rustc[Rust Compiler]
///     a -. inject mermaid.js .-> r
///     end
/// ```
pub fn example() {}

The diagram will appear in place of the mermaid code block, preserving all the comments around it. You can even add multiple diagrams!

To see it in action, go to the demo crate docs.rs page.


You can learn more about mermaid.js and what it can do in the mermaid's documentation MdBook


Aquamarine will automatically select the dark theme as a default, if the current rustdoc theme is either ayu or dark.

You might need to reload the page to redraw the diagrams after changing the theme.


Custom themes

Theming is supported on per-diagram basis, through the mermaid's %%init%% attribute.

Note: custom theme will override the default theme

/// ```mermaid
/// %%{init: {
///     'theme': 'base',
///     'themeVariables': {
///            'primaryColor': '#ffcccc', 
///            'edgeLabelBackground':'#ccccff', 
///            'tertiaryColor': '#fff0f0' }}}%%
/// graph TD
///      A(Diagram needs to be drawn) --> B{Does it have 'init' annotation?}
///      B -->|No| C(Apply default theme)
///      B -->|Yes| D(Apply customized theme)
/// ```


To learn more, see the Theming Section of the mermaid.js book

Separating diagrams from code

A diagram can be loaded from file to reduce clutter in the documentation comments.

Such diagram will always be placed under the rest of the document section. Reading diagrams from file can be combined with placing them into the doc-comment, to get multiple diagrams describing a single entity, however only one can be placed inside the file. (FIXME).

#[cfg_attr(doc, aquamarine::aquamarine, path = "./diagram.mermaid")]
pub fn example_foad_from_file() {}
# diagram.mermaid
graph LR
    s([Source]) --> a[[aquamarine]]
    r[[rustdoc]] --> f([Docs w/ Mermaid!])
    subgraph rustc[Rust Compiler]
    a -. load diagram.mermaid .-> r

In the wild

Crates that use aquamarine in their documentation

and other


A demo crate for aquamarine


~40K SLoC