Categories
Development Software

Working with Rust in VSCode’s devcontainer

Seamlessly run your Rust programs under a development container in Visual Studio Code.

Creation

In the directory of your choice (e.g. your Desktop),
create your Rust project:

{
    # Edit these variables:
    projDest="$HOME/Desktop"
    projName="hello-world"

    # Create our project
    cd "${projDest}"
    cargo new "${projName}" --bin

    # Bootstrap our project
    mkdir -pv "${projName}/.vscode"
    cd $_
    jo -p recommendations=$(jo -a "matklad.rust-analyzer" "formulahendry.code-runner") > extensions.json
    jo -p "code-runner.executorMap"="$(jo "rust"="cargo run # \$fileName")" > settings.json
    cd ..

    # Clean-up
    unset projDest projName
}

Which creates a directory with the following structure:

$HOME/Desktop/hello-world
├── .git
│   ├── HEAD
│   ├── config
│   ├── description
│   ├── hooks
│   │   └── README.sample
│   ├── info
│   │   └── exclude
│   ├── objects
│   │   ├── info
│   │   └── pack
│   └── refs
│       ├── heads
│       └── tags
├── .gitignore
├── .vscode
│   ├── extensions.json
│   └── settings.json
├── Cargo.toml
└── src
    └── main.rs

Table of contents:

  1. Introduction
  2. Installation
  3. Creation
  4. Configuration
  5. Development
  6. Without devcontainer?

Leave a Reply

Your email address will not be published. Required fields are marked *