CLI tool
rustviz/rustviz avatar
rustviz/rustviz

rustviz reads the borrow checker instead of your annotations

Interactively Visualizing Ownership and Borrowing for Rust

2,858 stars76 forksRustMIT

At a glance

What is it?
A teaching tool that draws Rust ownership and borrowing timelines by walking HIR and MIR, where all four entry points depend on one nightly-pinned rustc plugin and the only tagged release still points at the older annotation-based design.
Who is it for?
RustViz earns its place in a Rust teaching setup or an mdbook, where the picture has to match what the borrow checker actually did rather than what an author annotated by hand. It does not fit a pipeline that needs a nightly toolchain on every machine that builds it, and it does not suit anyone who expects a sandbox by default, because the library path runs the plugin as a local subprocess and only the playground binary opts into Docker.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository received new commits within the last day.
What is it written in?
Mainly Rust, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 22, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • rustviz/rustviz2,858 ★ · +7
Star history
Repository2026-10-042026-11-22
rustviz/rustviz2.9k2.9k

7 Stars in the last 49 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

The only tagged release is the version this repository replaced

There is one GitHub release here, tag rv1-final, published 2026-05-05 and named as the final annotation-based release. The annotation-based design is the earlier one: it read hand-annotated source. That tool now lives on the rv1-final branch and tag of this same repository, which is exactly where that release points. What sits on the default branch is a compiler-integrated rewrite that plugs into rustc directly and walks HIR/MIR, so the diagram reflects the real borrow checker's view of the program instead of a hand-curated approximation. The classroom tool described in the VL/HCC 2022 paper is the annotation-based one. The practical consequence is that a tagged install and the setup instructions on this page describe two different programs, and the only published artifact is the older of the two. The last commit to main is dated 2026-05-10, five days after that release.

Every entry point runs through one nightly-pinned plugin

The command line interface, the mdbook preprocessor and the library all share a single runtime dependency: the rustc plugin built from this workspace. It links against rustc_private, so it only loads under one specific nightly, and rust-toolchain.toml pins that nightly to nightly-2025-08-20. The plugin walks HIR and MIR for a single-file crate, emits a code panel SVG and a timeline panel SVG on stdout, and produces the cargo-rv-plugin and rv-plugin-driver binaries. It is built on Will Crichton's rustc_plugin and rustc_utils crates, the same family as Flowistry and Aquascope, and it is published to crates.io as rustviz-plugin. Because the pin lives in this repository rather than in a consumer's manifest, moving to another nightly is a change here and not something a downstream user can negotiate, and no second nightly is written down as supported.

rustviz init installs the toolchain and fetches the plugin

The documented fast path is two commands:

sh
cargo install rustviz-cli   # the `rustviz` CLI binary
rustviz init                # installs nightly-2025-08-20 + the plugin

`rustviz init` is not a config writer. It runs the underlying rustup toolchain install plus a cargo install against the canonical RustViz repository, so the same subcommand both changes your toolchain and decides where the plugin source comes from. Two flags matter for that reason. `--dry-run` prints exactly what would be done before anything happens, and `--plugin-git` or `--plugin-rev` point the plugin build at a fork instead of the canonical repository. Both are what you want before letting an init step touch a machine: one shows the plan, the other redirects the source of a component that links into the compiler.

Two panels become two files or one self-contained page

A single input file yields two drawings. `rustviz svg foo.rs` writes foo.code.svg and foo.timeline.svg, which is the mode meant for embedding the output in your own HTML or Markdown workflow. `rustviz html foo.rs` writes one self-contained HTML page with both SVGs inlined and the tooltip JavaScript embedded, and that page opens in any browser with no server and no external assets. The library splits the same pair at the API level:

rust
use rustviz_lib::Rustviz;

let rv = Rustviz::new(code)?;     // calls the plugin under the hood
fs::write("code.svg", rv.code_panel_string())?;
fs::write("timeline.svg", rv.timeline_panel_string())?;

`Rustviz::new(code)` shells out to the plugin and hands back the two panels as strings. The hover script both outputs depend on is shared code kept in the library crate and exported as `rustviz_lib::HELPERS_JS`, so an embedder that writes only the SVG files has to inline that script itself.

The library backend defaults to a local subprocess

The plugin executes whatever snippet it is handed, and the crate splits its backend in two: a local subprocess, which is the default for library use, and a sandboxed Docker path, which the playground binary opts into for untrusted input. That default is the part to read carefully before wiring RustViz into a pipeline, because anything built on rustviz-lib inherits local subprocess execution, meaning code you did not write is compiled on your machine unless you switch backends yourself. The hosted playground is the entry point that does not make that choice for you: its SPA loads from GitHub Pages while the compile API sits on Fly.io, and it selects docker instead. The runner image carries the rustviz/rustviz-runner tag. Apart from naming Docker, the crate docs do not state which container runtime that backend expects.

mdbook pays a compiler run per tagged code block

The mdbook preprocessor works by changing the language tag on a fence, from rust to rv:

rv
fn main() {
    let s = String::from("hello");
    println!("{}", s);
}

and by adding one entry to the book configuration:

toml
# book.toml
[preprocessor.rustviz]

Every rv tagged snippet is compiled through the plugin at book build time and the resulting SVGs are inlined into the rendered HTML, with tooltip glue for hover exploration. That design puts a cost on the book build itself: the nightly-pinned plugin has to be present on whichever machine builds the book, and the compiler is invoked once per tagged fence, so a book that mixes rv and rust fences pays for both paths. mdbook-rustviz/test-book/ is the small worked example, and the hands-on Rust tutorial at https://github.com/rustviz/tutorial is a full-scale book built this way, deployed at https://rustviz.github.io/tutorial/.

cargo xtask uninstall is not a rollback of setup

`cargo xtask setup` is the canonical bootstrap for working on RustViz, and it is a wider operation than the CLI path: toolchain plus plugin install, plus the frontend build, plus the runner image. Its counterpart is `cargo xtask uninstall`, whose help output spells out what it touches and what it leaves alone, and by default it spares the rustup toolchain and the cargo target/ tree. A full uninstall therefore leaves a pinned nightly installed and the build tree in place, which is the sensible default for a toolchain other projects share. The xtask driver itself is pure Rust, so the same commands run on Linux, macOS and Windows. The workspace declares six members under resolver 2: the four entry points, playground, mdbook-rustviz, rustviz-cli and rustviz-lib, plus rustviz-plugin and xtask.

Parallel clones race for one cargo home and one docker tag

Several checkouts on different branches share `~/.cargo`, and setup runs cargo install, so each clone's setup races the others for the single file `~/.cargo/bin/rustviz`. Concurrent playground builds collide on the rustviz/rustviz-runner docker tag, and the playground bind address is the third shared resource. The isolation path shipped with the repository is `.envrc.example` for direnv, which gives each checkout its own CARGO_HOME and adds knobs for the docker tag and the bind address:

sh
brew install direnv
echo 'eval "$(direnv hook zsh)"' >> ~/.zshrc   # then restart your shell
cp .envrc.example .envrc
direnv allow

After that, any shell you cd into, and anything those shells launch, inherits the per-clone cargo home. The rustup toolchain stays shared on purpose, because every clone pins the same nightly. The direnv instructions are written for brew and zsh, which makes this the one part of the bootstrap that is not cross-platform.

Editorial conclusion

RustViz earns its place in a Rust teaching setup or an mdbook, where the picture has to match what the borrow checker actually did rather than what an author annotated by hand. It does not fit a pipeline that needs a nightly toolchain on every machine that builds it, and it does not suit anyone who expects a sandbox by default, because the library path runs the plugin as a local subprocess and only the playground binary opts into Docker. Before adopting it, check the plugin's nightly pin against your own toolchain, read what `rustviz init --dry-run` would do on your machine, and confirm that the version you install is the compiler-integrated one rather than the rv1-final tag, which still points at the annotation-based tool.

Frequently asked questions

What does rustviz need installed before it can render a diagram?

A matching nightly toolchain and the rustc plugin from this workspace. The plugin links against rustc_private, so `rustviz init` installs nightly-2025-08-20 together with it, and rust-toolchain.toml pins that same nightly for anyone building from a checkout.

What is the difference between rustviz on the default branch and the rv1-final release?

rv1-final, published 2026-05-05, is the final release of the annotation-based RustViz, which read hand-annotated source. The default branch holds the compiler-integrated rewrite that walks HIR and MIR through rustc directly, and the old tool is kept on the rv1-final branch and tag.

Does the rustviz playground require a local install?

No. The hosted playground takes a pasted snippet in a CodeMirror editor and returns the visualization, with the SPA loaded from GitHub Pages and the compile API on Fly.io. The same playground is also available as the playground/ crate in this workspace for running locally.

How do I embed a rustviz diagram in an mdBook?

Tag a code fence `rv` instead of `rust` and add `[preprocessor.rustviz]` to book.toml. Each tagged snippet is compiled through the plugin at book build time and its SVGs are inlined into the rendered HTML, with tooltip glue for hover exploration.

What files does the rustviz CLI write for one source file?

Either two files or one page. `rustviz svg foo.rs` writes foo.code.svg and foo.timeline.svg for your own HTML or Markdown workflow, while `rustviz html foo.rs` writes a single self-contained HTML page with both SVGs and the tooltip script embedded.

Official sources

  1. License: MIT
  2. Project website
  3. README
  4. Releases
  5. rustviz/rustviz on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/rustviz-rustviz.svg)](https://hysenlabs.com/projects/rustviz-rustviz)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/rustviz-rustviz.svg)](https://hysenlabs.com/projects/rustviz-rustviz)

Was this useful?