RustOwl

repository·main·Indexed 26 days ago

https://github.com/cordx56/rustowl

A visualization tool for Rust (v0.4.0) that helps developers understand ownership and lifetimes through color-coded underlines in supported editors. It provides visual indicators for variable lifetimes, immutable and mutable borrowing, value moves, and lifetime errors. RustOwl supports VS Code, Vscodium, Neovim, Emacs, IntelliJ/RustRover, and Sublime Text via an LSP server.

Tokens
16K
Snippets
36
Records
123
Agent score
89%

What's inside rustowl

  1. Overview of RustOwl

    main

    RustOwl is a tool designed to visualize ownership movement and lifetimes of variables in Rust code. It helps with debugging and optimization by providing visual feedback through underlines when you hover over variables or function calls in supported editors.

    Visual Indicators:

    • 🟩 Green: Variable's lifetime
      • Definitely live: Variable is provably initialized on every path.
      • Maybe live (wavy): Variable is initialized on some paths but may have been moved, dropped, or be uninitialized on others.
    • 🟦 Blue: Immutable borrowing
    • 🟪 Purple: Mutable borrowing
    • 🟧 Orange: Value moved or function call
    • 🟥 Red: Lifetime error (e.g., diff between actual and expected lifetime, or invalid overlapped mutable/shared references).
  2. Quick Start with RustOwl

    main

    To begin using RustOwl, follow these steps:

    1. Install the RustOwl LSP server and the corresponding extension for your editor (refer to docs/installation.md).
    2. Open a Rust Cargo workspace in your editor.
    3. Open a Rust source file (.rs).
    4. Place your cursor on a variable or function call and wait for a short idle time to see the ownership and lifetime visualizations.
  3. Quick Start with RustOwl VS Code Extension

    main

    To use RustOwl in VS Code, install the extension from the Marketplace or Open VSX. The extension automatically downloads and runs the rustowl binary upon activation.

    1. Install the extension in VS Code.
    2. Open a Rust Cargo workspace.
    3. Save a Rust file and hover over a variable after a short idle time to see decorations.
  4. Quick Start: Install RustOwl using the installer script

    main

    The fastest way to install RustOwl is by using the official installation script. This is the recommended method for a quick setup.

    curl -L https://raw.githubusercontent.com/cordx56/rustowl/refs/heads/main/scripts/installer | sh
  5. Set up the Rust development environment

    main

    RustOwl uses a rust-toolchain.toml file to automatically manage the required nightly compiler version. For standard development (building, testing, or installing), you can use standard cargo commands.

    Building with Stable Rust (for rustowlc component)

    To distribute release binaries, the rustowlc component is compiled using the stable Rust compiler. This requires setting the RUSTC_BOOTSTRAP=1 environment variable.

    Note: Using this method is officially discouraged; refer to the Unstable Book for details.

    To build using the toolchain specified in the project's channel file, use the provided automation script:

    ./scripts/build/toolchain cargo build --release

    Or manually (replace 1.89.0 with the desired version):

    RUSTC_BOOTSTRAP=1 rustup +1.89.0 run cargo build --release
    ./scripts/build/toolchain cargo build --release
  6. Install and set up RustOwl for Emacs

    main

    To use RustOwl in Emacs, you must first install the rustowl executable (refer to docs/installation.md). Then, install the Emacs package using either elpaca or use-package.

    Once installed, open a Rust Cargo workspace. By default, placing your cursor on a variable and waiting for the timeout (2.0 seconds) will display overlays showing lifetime and borrow information.

    ; Elpaca example
    (elpaca
      (rustowl
        :host github
        :repo "cordx56/rustowl"))
    
    ; Use-package example
    (use-package rustowl
      :after lsp-mode)
  7. Quick Start for VS Code and Vscodium

    main

    To use RustOwl in VS Code or Vscodium, follow these steps:

    1. Prerequisites:
      • Install cargo (via rustup).
      • Install VS Code or Vscodium.
    2. Installation:
    3. Activation:
      • RustOwl is installed automatically when the extension is activated.
      • In Vscodium, the extension runs automatically when you save any Rust program in a cargo workspace.
      • The initial analysis may take time, but subsequent runs use compile caching to speed up analysis.