Rust on Windows 11, My Complete Setup Guide

Install Rust
- From this page
- Download then run
rustup-init.exe
(64b) - Open a terminal and run this command
rustc --version
just to make sure everything is OK.

Install VSCode
- From this page, download and install VSCode
Install rust-analyzer extension for VSCode
- Open VSCode then from
- The extensions pane, on the left
- Or from this page
- Install
rust-analyzer

Setup Linting
- From VSCode
CTRL + ,
to open theSettings
- Type in
rust-analyzer check
- Replace
check
byclippy
in theRust-analyzer > Check : Command
(see below)

Setup Inlay Hints
By default, I find the type information a little too invasive, unnecessarily lengthening the lines of code and blurring readability. They’re very useful, but I’d like to display them on demand.
- In VSCode
CTRL + ,
to open theSettings
- Enter
inlay
- Select
offUnlessPressed
- Then press
CTRL + ALT
in the editor when you want to check the types of the variables

Not pressing CTRL+ALT

Pressing CTRL+ALT
Do you see the i32
and u8
in gray ?

Setup line width
- When saving file the formatter may reformat long lines
- I create a
Rustfmt.toml
file at the root of the project - So far my
Rustfmt.toml
has only only one line
max_width = 200
Debugging code 1/2
- Install Build Tools for Visual Studio
- This is my preferred option because I code in C++.. It comes with everything : compiler, linker, debugger…
- Others may install CodeLLDB VSCode extension. It only provides a debugger. May be enough if you plan to only use Rust.

- Open a terminal
- Create a project (
cargo new rust_test4web
)

cd .\rust_test4web\
code .
- Copy the lines below for example in the file
src\main.rs
fn main() {
let x = 5;
println!("{}", x);
let y = 6u8;
println!("{}", y);
let mut zoubida = 18;
println!("{}", zoubida);
zoubida = 19;
println!("{}", zoubida);
}
- Set a breakpoint on line 8
- See below the red dot on the left
- You can either click or strike
F9
when the cursor is on the line of interest
- In the editor click on the “Debug” (see below in the red rectangle)

- A
target/debug
directory is created - While looking for the outputs, keep in mind they occurs in the
DEBUG CONSOLE
not in theTERMINAL
. See below

- Once the code stops on the line, you can then inspect variables, go step by step…

Debugging code 2/2
If you want to debug code when you press F5 and have more options (like passing arguments for example)
- Create a
.vscode
folder at the root of the project - Create a
tasks.json
file in that directory - Copy and paste the lines below
{
"version": "2.0.0",
"tasks": [
{
"label": "cargo-build-debug",
"type": "cargo",
"command": "build",
"args": [],
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "cargo-build-release",
"type": "cargo",
"command": "build",
"args": [
"--release"
],
"problemMatcher": [
"$rustc"
]
}
]
}
- Save the
.json
file (CTRL+S
) - Create a
launch.json
file in the.vscode
folder - Copy and paste the lines below
{
"version": "0.2.0",
"configurations": [
{
"type": "cppvsdbg",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/target/debug/${workspaceFolderBasename}.exe",
"args": [],
"cwd": "${workspaceFolder}",
"environment": [
{
"name": "RUST_BACKTRACE",
"value": "short"
}
],
"preLaunchTask": "cargo-build-debug"
},
{
"type": "cppvsdbg",
"request": "launch",
"name": "Release",
"program": "${workspaceFolder}/target/release/${workspaceFolderBasename}.exe",
"args": [],
"cwd": "${workspaceFolder}",
"environment": [
{
"name": "RUST_BACKTRACE",
"value": "short"
}
],
"preLaunchTask": "cargo-build-release"
}
]
}
Here is how it should look like

- On the left hand side, click on the
Run & Debug
icon (the bug and the triangle icon,CTRL+SHIFT+D
otherwise)- Make sure the current config in the list box is set on
Debug
- See below
- Make sure the current config in the list box is set on

- Switch back to the code
- Set a breakpoint somewhere
- Press
F5
- A
target/debug
directory is created - The debugger stops on the breakpoint
- A

3 ways to run the Debug version of your code without the debugger
Make sure the current configuration is still Debug
Option 1 :
- If you press
CTRL+F5
this run the Debug version of the code but without debugging it - So, the debugger does not stop on the breakpoint.
Option 2 :
- In the editor
- Click
Run
(instead ofDebug
)

Option 3 :
- In VSCode
- Open a terminal
CTRL+ù
(azerty keyboard) - Enter
cargo run

Create and Run a Release Version 1/2
- On the left hand side, click on the
Run & Debug
icon (CTRL+SHIFT+D
)- Make sure the current config is set on
Release
- Make sure the current config is set on

- You can either press F5 or CTRL+F5
- A
target/release
directory is created
Create and Run a Release Version 2/2
- In VSCode
- Open a terminal
CTRL+ù
(azerty keyboard) - Enter
cargo run --release
How to build only (either, Debug or Release version)
Option 1 :
- Click on
Terminal/Run Task...
option - Select
cargo-build-debug
orcargo-build-release

Option 2 :
- Open a terminal in VSCode
- Either type
cargo build
orcargo build --release
Optional
Color Syntax for .toml
files
- In VSCode install “Even Better TOML” extension

Get hints help & support while editing cargo.toml files
- Mostly helps when editing versions of the crates to be included in the project
- In VSCode install “dependi” extension (crates extension is now deprecated)

This may help
- Read this page
- Enter
rustup doc
in a terminal