Skip to content

cordx56/rustowl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

RustOwl

Visualize ownership and lifetimes in Rust for debugging and optimization

RustOwl visualizes ownership movement and lifetimes of variables. When you save Rust source code, it is analyzed, and the ownership and lifetimes of variables are visualized when you hover over a variable or function call.

RustOwl visualizes those by using underlines:

  • đźź© green: variable's actual lifetime
  • 🟦 blue: immutable borrowing
  • 🟪 purple: mutable borrowing
  • đźź§ orange: value moved / function call
  • 🟥 red: lifetime error
    • diff of lifetime between actual and expected, or
    • invalid overlapped lifetime of mutable and shared (immutable) references

Detailed usage is described here.

Currently, we offer VSCode extension, Neovim plugin and Emacs package. For these editors, move the text cursor over the variable or function call you want to inspect and wait for 2 seconds to visualize the information. We implemented LSP server with an extended protocol. So, RustOwl can be used easily from other editor.

Table Of Contents

Support

If you're looking for support, please consider checking all issues, existing discussions, and starting a discussion first!

Also, you can reach out to us on the Discord server provided above.

Quick Start

Here we describe how to start using RustOwl with VS Code.

Prerequisite

  • cargo installed
    • You can install cargo using rustup from this link.
  • Visual Studio Code (VS Code) installed

We tested this guide on macOS Sequoia 15.3.2 on arm64 architecture with VS Code 1.99.3 and cargo 1.88.0.

VS Code

You can install VS Code extension from this link. RustOwl will be installed automatically when the extension is activated.

Vscodium

You can install Vscodium extension from this link. RustOwl will be installed automatically when the extension is activated.

After installation, the extension will automatically run RustOwl when you save any Rust program in cargo workspace. The initial analysis may take some time, but from the second run onward, compile caching is used to reduce the analysis time.

Other editor support

We support Neovim and Emacs. You have to install RustOwl before using RustOwl with other editors.

You can also create your own LSP client. If you would like to implement a client, please refer to the The RustOwl LSP specification.

Neovim

Minimal setup with lazy.nvim:

{
  'cordx56/rustowl',
  version = '*', -- Latest stable version
  build = 'cargo binstall rustowl',
  lazy = false, -- This plugin is already lazy
  opts = {},
}
Recommended configuration: Click to expand
{
  'cordx56/rustowl',
  version = '*', -- Latest stable version
  build = 'cargo binstall rustowl',
  lazy = false, -- This plugin is already lazy
  opts = {
    client = {
      on_attach = function(_, buffer)
        vim.keymap.set('n', '<leader>o', function()
          require('rustowl').toggle(buffer)
        end, { buffer = buffer, desc = 'Toggle RustOwl' })
      end
    },
  },
}

Default options:

{
  auto_attach = true, -- Auto attach the RustOwl LSP client when opening a Rust file
  auto_enable = false, -- Enable RustOwl immediately when attaching the LSP client
  idle_time = 500, -- Time in milliseconds to hover with the cursor before triggering RustOwl
  client = {}, -- LSP client configuration that gets passed to `vim.lsp.start`
  highlight_style = 'undercurl', -- You can also use 'underline'
}

When opening a Rust file, the Neovim plugin creates the Rustowl user command:

:Rustowl {subcommand}

where {subcommand} can be one of:

  • start_client: Start the rustowl LSP client.
  • stop_client: Stop the rustowl LSP client.
  • restart_client: Restart the rustowl LSP client.
  • enable: Enable rustowl highlights.
  • disable: Disable rustowl highlights.
  • toggle: Toggle rustowl highlights.

Emacs

Elpaca example:

(elpaca
  (rustowlsp
    :host github
    :repo "cordx56/rustowl"))

You have to install RustOwl LSP server manually.

RustRover / IntelliJ IDEs

There is a third-party repository that supports IntelliJ IDEs. You have to install RustOwl LSP server manually.

Architecture / OS / package repositories

One of the easiest way to install RustOwl is using cargo-binstall.

cargo binstall rustowl

Toolchain is automatically Downloaded and unpacked.

Windows

We have a winget package, install with:

winget install rustowl

Archlinux

We have an AUR package. It downloads prebuilt binaries from release page. Run:

yay -S rustowl-bin

If you would like to build from that version instead:

yay -S rustowl

Replace yay with your AUR helper of choice.

We also have a git version, that builds from source:

yay -S rustowl-git

Nix flake

There is a third-party Nix flake repository in the Nix community.

GitHub Release

Download only rustowl executable from release page and place it into the place you desire. Toolchain is automatically Downloaded and unpacked.

Build manually

There is a build guide to build RustOwl or extensions.

Note

In this tool, due to the limitations of VS Code's decoration specifications, characters with descenders, such as g or parentheses, may occasionally not display underlines properly. Additionally, we observed that the println! macro sometimes produces extra output, though this does not affect usability in any significant way.

About

Visualize Ownership and Lifetimes in Rust

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

 
 
 

Contributors 24