• Stars
    star
    495
  • Rank 88,974 (Top 2 %)
  • Language
    Rust
  • License
    MIT License
  • Created almost 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Inline diagrams for rustdoc with mermaid.js

Aquamarine

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.

light

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

Dark-mode

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.

light

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)
/// ```

custom

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
    end

In the wild

Crates that use aquamarine in their documentation

and other

More Repositories

1

Reed-Solomon

Reed Solomon BCH encoder and decoder
C++
100
star
2

reed-solomon-rs

Reed-Solomon BCH encoder and decoder with support of no_std environment
Rust
26
star
3

batch_resolve

Fast asynchronous DNS batch resolver
Rust
26
star
4

tdjson-rs

TDLIB Json Client for Rust
Rust
12
star
5

rust_shm_ipc

An example implementatation of synchronized queue for inter-process communication in shared memory
Rust
10
star
6

tdjson-sys

TDLIB Json Client Rust FFI Bindings
Rust
9
star
7

rustyrobot

Rust
8
star
8

maze-generator_offscreen

Offscreen maze generator. Alternated renderer of labyrinth to OSMesa and cleaned code.
Groff
7
star
9

disciplinator

A motivation tool to reduce sedentary lifestyle health implications
Rust
3
star
10

maze-generator

Labyrinth generator and solver implemented in C/OpenGL
C
3
star
11

primitive-map-rs

[WIP] Blazing fast [Integer -> T: Clone] Map crate
Rust
3
star
12

rustylang

Rust
3
star
13

autorand-rs

Automatic random generation for any struct or enum. Make your fuzzing easier!
Rust
3
star
14

akkadia

The most extensible Language Server
Rust
2
star
15

backontime

Cross-platform filesystem notification aware backup trigger tool
Rust
2
star
16

pizip

Rust
2
star
17

try-block-rs

Macro that makes it simple to make error-catching blocks
Rust
2
star
18

disciplinator-android-app

[DEPRECATED] An android app to display the information from Disciplinator Headmaster
Java
1
star
19

htoi

just a lazy time "rewrite it in rust" game I played with my friend
Rust
1
star
20

DynamicCaller

Caller class allowing to call C++ functions by name.
C++
1
star
21

redstone

Rust
1
star
22

dist2steps

Distance to Steps fitness conversion tool
Rust
1
star
23

rust_plugin_test

Statically linked / dynamically configured plugins test with Rust
Rust
1
star
24

libVK

VK API wrapper for C++11
C++
1
star
25

autolog-rs

Inner custom attribute for automated trace logging and time measurements
Rust
1
star
26

example-tokio-cpupool

Rust
1
star
27

todo

Every developer must once write his own ToDo List. Now in Rust.
Rust
1
star
28

dotfiles

My .dotfiles w/ dotter templates
Shell
1
star
29

rust-vs-haskell-special-olimpiade

Rust
1
star
30

example-useless-proc-macro

Rust
1
star
31

moonlander

My moonlander layout, heavily inspired by github.com/optozorax/moonlander
C
1
star