DEV Community

Thiago Massari Guedes
Thiago Massari Guedes

Posted on

19 3

Developing in Rust using Visual Studio Code

Developing in Rust using Visual Studio Code

Two of the best features when using an IDE are auto completing and debugging. Fortunately, we can have both with VSCode.

Source of this post: http://thiago.rocks/view/20200512_vscode_with_rust

Install Rust

Go to rust website and follow the install procedure

Then use nightly channel to get the latest version of the toolchain.

# Install nightly toolchain
$ rustup toolchain install nightly

# Set nightly toolchain as default
$ rustup default nightly
Enter fullscreen mode Exit fullscreen mode

Install related Visual Studio Code extensions

Install those 2 extensions:

After installing, open a rust file in the editor and you will be asked:

Some rust components not installed. Install it?

Click Yes

Auto completing the code

This is how auto complete looks:

auto complete 1

And now with documentation

auto complete 2

Debugging the code

Creating the run configuration for the project

First: Create a launch.json using lldb

Press Ctrl + Shift + P and select Debug: Open launch.json

Paste this content and replace hello with the name of your project

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "lldb",
      "request": "launch",
      "name": "Launch",
      "args": [],
      "program": "${workspaceFolder}/target/debug/hello",
      "windows": {
        "program": "${workspaceFolder}/target/debug/hello.exe"
      },
      "cwd": "${workspaceFolder}",
      "stopOnEntry": false,
      "sourceLanguages": [
        "rust"
      ]
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Now, you have to build and run with lldb debugger attached.

  • To build: Press Ctrl + Shift + B
  • Toggle breakpoints: F9
  • To debug: Press F5

This is the debugger inspecting the content of the variable

debug

That's all. Quite simple, with a bit of tweaking.

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

đź‘‹ Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay