Visual Studio Code launch.json debug configuration (build Rust with cargo)

Hello, in order to debug my program I have to perform several steps before I can start debugging:

  1. Save the code files (there is only main.rs so far)
  2. run cargo build in the terminal
  3. press F5 to start debugging

I would like to reduce this into a single step, meaning pressing F5 would automatically save my file, build the code and start debugging.

Maybe somebody can point me to an example launch.json, this is what I got so far:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceFolder}/target/debug/${workspaceRootFolderName}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true
        }
    ]
}

I found out how it works.

\guessing_game\.vscode\launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceFolder}/target/debug/${workspaceRootFolderName}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "preLaunchTask": "cargo build"
        }
    ]
}

\guessing_game\.vscode\tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "cargo build",
            "type": "cargo",
            "subcommand": "build",
            "problemMatcher": [
                "$rustc"
            ]
        }
    ]
}