Rust | IntelliJ IDEA (2024)

The Rust plugin equips IntelliJIDEA with full-fledged Rust support. This guide overviews the basic procedures to get you started. You can find more information about the supported features in RustRover documentation.

Install Rust plugin

  1. Launch IntelliJIDEA. On the Welcome screen, click Plugins.

    If you already have a project opened, go to Settings (Ctrl+Alt+S) | Plugins.

  2. Select the Marketplace tab and search for the Rust plugin.

    Rust | IntelliJIDEA (1)
  3. Click Install and wait for the download to complete.

    Restart the IDE if prompted.

The plugin will be activated automatically. To double-check it is active, navigate to Help | Register and select Rust in the left-hand pane.

Rust | IntelliJIDEA (2)

To develop in Rust, you need several basic tools: a compiler, a package manager, a formatter, and so on. A set of these tools is referred to as a toolchain. You will also need the Rust Standard Library.

If you have already opened a project and the Rust toolchain is missing, you will see a notification banner right above the editor:

Rust | IntelliJIDEA (3)
  1. Click Set up toolchain.

    Alternatively, open IDE settings (Ctrl+Alt+S) and select Languages & Frameworks | Rust.

  2. If the Rust toolchain is not detected, Toolchain version will display N/A. Click the Install Rustup button – IntelliJIDEA will attempt to install both the toolchain and the standard library.

    Rust | IntelliJIDEA (4)
  3. Once the installation is complete, IntelliJIDEA will automatically detect its location, populating the Toolchain version and the Standard library path.

  4. Click OK to apply the settings.

Open or create a Rust project

You have three options to start working on a Rust project.

Create a new Cargo project

  1. Launch IntelliJIDEA.

    Do one of the following:

    • Click New Project on the Welcome screen.

    • Select File | New | Project from the main menu.

    • (Available in the new UI) Click the Project widget in the main window header and select New Project.

      Rust | IntelliJIDEA (5)
  2. In the left-hand pane, make sure Rust is selected.

  3. Specify the project location and name.

  4. Specify the location of the Rust toolchain and standard library.

    If the toolchain and standard library are installed, IntelliJIDEA will detect them automatically. Otherwise, you will be suggested to download Rustup.

    Rust | IntelliJIDEA (6)
  5. Select the desired project template and click Create.

Rust | IntelliJIDEA (7)

Open a local Cargo project

  1. In the main menu, go to File | Open. In the file chooser, select the directory containing the root Cargo.toml file (or Cargo.toml itself) and click Open:

    Rust | IntelliJIDEA (8)
  2. In the dialog that opens, select Open as project.

    Rust | IntelliJIDEA (9)
  3. When opening the project for the first time, IntelliJIDEA will prompt you to confirm that you consider it safe.

    Rust | IntelliJIDEA (10)

    Click Trust Project if you are certain the project poses no threats and you would like to enable all IDE features. If you have any doubts, select Preview in Safe Mode. For more information, refer to Project security.

Rust | IntelliJIDEA (11)

Clone a repository from VCS

  1. In the main menu, go to File | New | Project from Version Control or click Get from VCS on the Welcome screen.

  2. Specify the repository URL and the destination directory. Click Clone:

    Rust | IntelliJIDEA (12)

Explore the workspace and features

The plugin's feature set is designed to simplify the Rust development process. Let's take a closer look at what it has to offer.

Syntax highlighting and code reference

To help you quickly read and understand Rust code, the plugin provides highlighting, Inlay hints, macro expansion, quick access to documentation, and more.

Rust | IntelliJIDEA (13)

Here are some shortcuts you may find useful:

Action

Shortcut

Expand macro

Alt+Enter

Go to declaration

Ctrl+Click

Get type info

Ctrl+Shift+P

Quick documentation

Ctrl+Q

Quick definition

Ctrl+Shift+I

For more information, refer to RustRover documentation.

Code analysis and error reporting

To help you fight errors and inconsistencies in code, the plugin offers built-in inspections and integrates with external linters.

For a summary of all detected problems, use the Inspections widget in the upper-right corner of the editor. To see the details, click the widget and refer to the Problems tool window (or select View | Tool Windows | Problems):

Rust | IntelliJIDEA (14)

For more information, refer to Code inspections and External linters in RustRover documentation.

Formatting

You can easily format your code using either the IDE's built-in formatter (enabled by default) or Rustfmt.

Enable (or disable) Rustfmt instead of the built-in formatter

  1. Open settings by pressing Ctrl+Alt+S and navigate to Languages & Frameworks | Rust | Rustfmt.

  2. To enable Rustfmt, set the Use Rustfmt instead of built-in formatter checkbox. To disable Rustfmt, clear the checkbox.

    Rust | IntelliJIDEA (15)
  3. Click OK to apply the changes.

Reformat a file

  1. Open the file you want to reformat in the editor.

  2. Press Ctrl+Alt+Shift+L or select Code | Reformat File.

  3. In the Reformat File dialog, select additional options if necessary and click Run.

    Rust | IntelliJIDEA (16)

For more information, refer to Reformat code and Rustfmt.

The Cargo tool window

The Cargo tool window is designed to help you with Cargo tasks. By default, it is pinned to the tool windows bar. You can show or hide it by clicking the window indicator on the sidebar (alternatively, select View | Tool Windows | Cargo).

Rust | IntelliJIDEA (17)

For more information, refer to RustRover documentation.

Sharing code in Playground

You can share your code in Rust Playground without leaving the editor.

  1. Select the code fragment you'd like to share (otherwise, the IDE will copy the whole file).

  2. Right-click and choose Rust | Share in Playground.

IntelliJIDEA will create a GitHub Gist and display a notification popup with a link to the playground.

Rust | IntelliJIDEA (18)

For more features, refer to RustRover documentation.

Build and run

Use the Build action to compile your code and Run to execute it. There are several ways to perform these actions:

Build/run Rust code

  • To build or run a particular target, open the Cargo tool window (View | Tool Windows | Cargo) and double-click the target.

    Rust | IntelliJIDEA (19)
  • To run from a particular entry point, locate it in the editor, click Rust | IntelliJIDEA (20) in the gutter, and select Run:

    Rust | IntelliJIDEA (21)
  • To run a particular file or module, open the Project view, right-click the necessary file or module, and select Run:

    Rust | IntelliJIDEA (22)
  • If you want to build or run code using a predefined configuration (with custom parameters and settings), select it in the switcher on the main toolbar and:

    • click Rust | IntelliJIDEA (23) to build (Ctrl+F9)

    • click Rust | IntelliJIDEA (24) to run (Shift+F10)

    Rust | IntelliJIDEA (25)
  • You can always build/run using a Cargo command.

For more information, refer to RustRover documentation.

Debug

Rust plugin provides a full-fledged debugger – with breakpoints, variable monitoring, stepping, memory and disassembly views, and other handy features.

Start a debug session

  • To start debugging from a particular entry point, locate it in the editor, click Rust | IntelliJIDEA (26) in the gutter, and select Debug:

    Rust | IntelliJIDEA (27)
  • To debug code using a predefined configuration (with custom parameters and settings), select it in the configuration switcher on the main toolbar and click Rust | IntelliJIDEA (28):

    Rust | IntelliJIDEA (29)
  • You can always start a debug session by running a Cargo command.

For more information, refer to Start the debugger session.

Learn how to perform basic debugging actions from these guides:

  • Setting breakpoints

  • Using watches

  • Stepping through

  • Viewing memory and disassembly code representation

Rust | IntelliJIDEA (30)

For more information, refer to RustRover documentation.

Test

You will likely support your code with tests, doctests, and/or benchmarks. Here are a few quick ways to run them:

Run test(s), doctest(s), or benchmark(s)

  • To run a single test or doctest, open it in the editor, click Rust | IntelliJIDEA (31) in the gutter, and select Run:

    Rust | IntelliJIDEA (32)
  • To run a test/benchmark target, open the Cargo tool window (View | Tool Windows | Cargo) and double-click the target:

    Rust | IntelliJIDEA (33)
  • You can always run tests using a Cargo command.

The Run tool window will open, automatically displaying the results:

Rust | IntelliJIDEA (34)

For more information, refer to RustRover documentation.

Run with code coverage

The plugin provides code coverage analysis for Rust code.

Run with Code Coverage

To get code coverage statistics, do one of the following:

  • Locate the desired entry point, click Rust | IntelliJIDEA (35) in the gutter, and select Run with Coverage:

    Rust | IntelliJIDEA (36)
  • Locate the necessary file in Project view, right-click, and select Run with Coverage:

    Rust | IntelliJIDEA (37)
  • If you want to run a predefined configuration (with custom parameters and settings), select it in the switcher on the main toolbar, then press Rust | IntelliJIDEA (38) and select Run with Coverage:

    Rust | IntelliJIDEA (39)

The Coverage tool window (View | Tool Windows | Coverage) will open, automatically displaying the results:

Rust | IntelliJIDEA (40)

For more information, refer to Code coverage.

To learn more about Rust support, refer to RustRover documentation or contact our support team.

Rust plugin vs. RustRover

Differences in the feature set

RustRover

CLion+Rust plugin

IntelliJ IDEA Ultimate+Rust plugin

Debugger

For Linux, both LLDB and GDB are available. For macOS, only LLDB is available. For Windows, LLDB is supported for MSVC, GDB is supported for GNU. Learn more

For Windows and Linux, both LLDB and GDB are available. For macOS, only LLDB is available.

Allows to debug on-chip

For Windows and Linux, both LLDB and GDB are available (Native Debugging Support free plugin required). For macOS, only LLDB is available.

Profiler

Available on macOS, Linux, and WSL

Available on macOS, Linux, and WSL

Rust | IntelliJIDEA (41)

Valgrind Memcheck

Rust | IntelliJIDEA (42)

Available on Linux, WSL, and macOS (10.12 or later)

Rust | IntelliJIDEA (43)

Database support

Via paid plugin

Rust | IntelliJIDEA (44)

Rust | IntelliJIDEA (45)

Language support

RustRover

CLion+Rust plugin

IntelliJ IDEA Ultimate+Rust plugin

Rust

Rust | IntelliJIDEA (46)

Rust | IntelliJIDEA (47)

Rust | IntelliJIDEA (48)

Java, Groovy, Kotlin

Rust | IntelliJIDEA (49)

Rust | IntelliJIDEA (50)

Rust | IntelliJIDEA (51)

C/C++, Objective С/С++

Rust | IntelliJIDEA (52)

Rust | IntelliJIDEA (53)

Rust | IntelliJIDEA (54)

Python

Via free plugin

Rust | IntelliJIDEA (55)

Rust | IntelliJIDEA (56)

JavaScript, TypeScript

Only basic JavaScript & TypeScript support

Rust | IntelliJIDEA (57)

Rust | IntelliJIDEA (58)

HTML, CSS

Rust | IntelliJIDEA (59)

Rust | IntelliJIDEA (60)

Rust | IntelliJIDEA (61)

Sass, SCSS, Less

Via Sass and Less free plugins

Rust | IntelliJIDEA (62)

Rust | IntelliJIDEA (63)

XML, JSON, YAML, XSLT, XPath

Rust | IntelliJIDEA (64)

Rust | IntelliJIDEA (65)

Rust | IntelliJIDEA (66)

Markdown

Rust | IntelliJIDEA (67)

Rust | IntelliJIDEA (68)

Rust | IntelliJIDEA (69)

Last modified: 24 June 2024

Run/Debug Configuration: Spork DRbShell scripts

Rust | IntelliJ IDEA (2024)
Top Articles
Latest Posts
Article information

Author: Ray Christiansen

Last Updated:

Views: 6240

Rating: 4.9 / 5 (49 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Ray Christiansen

Birthday: 1998-05-04

Address: Apt. 814 34339 Sauer Islands, Hirtheville, GA 02446-8771

Phone: +337636892828

Job: Lead Hospitality Designer

Hobby: Urban exploration, Tai chi, Lockpicking, Fashion, Gunsmithing, Pottery, Geocaching

Introduction: My name is Ray Christiansen, I am a fair, good, cute, gentle, vast, glamorous, excited person who loves writing and wants to share my knowledge and understanding with you.