User-defined Playground

Rust Programming Playground

A disposable Rust development environment with stable, beta, and nightly toolchains, bacon, cargo-nextest, rustfmt, clippy, rust-analyzer, and the musl target pre-installed.

Startup configuration
rust-01
Rust Programming playground: A disposable Rust development environment with stable, beta, and nightly toolchains, bacon, cargo-nextest, rustfmt, clippy, rust-analyzer, and the musl target pre-installed.

A disposable Rust development environment. Stable 1.99.0, beta, and nightly toolchains, rustfmt, clippy, rust-analyzer, codelldb, and the musl cross-compilation target are all pre-installed. Full IDE support via VS Code with a native debugger. Runs on 4 vCPU / 10 GiB RAM / 100 GiB disk.

Nothing is persisted once the playground stops.

What's included

  • rustc / cargo (stable 1.99.0 as default, beta, nightly)
  • rustfmt code formatter and clippy linter (all three toolchains)
  • rust-src so rust-analyzer can resolve the standard library
  • bacon: background check, lint and test runner
  • cargo-watch: reruns any cargo command on every save
  • cargo-nextest: faster test runner with clearer output
  • cargo-expand: shows code after macro expansion
  • cargo-audit: scans dependencies for known vulnerabilities
  • cargo-binstall: installs prebuilt cargo tools in seconds
  • rust-analyzer for IDE intelligence in VS Code, with clippy on save and format on save
  • codelldb native debugger in VS Code
  • x86_64-unknown-linux-musl target for static binaries
  • A C toolchain, pkg-config, and libssl-dev for the common -sys crates
  • zsh with a starship prompt that shows the full path, git branch, Rust version and crate version, plus autosuggestions, syntax highlighting and atuin history search
  • tmux, lazygit, bat, eza, fd, ripgrep, zoxide, fzf, btop, fastfetch
  • delta as the git pager, so git diff and git log -p show syntax-highlighted diffs with line numbers
  • Catppuccin Mocha across the prompt, VS Code, bat, delta, fzf and tmux

Key commands

New project

cargo new hello && cd hello
cargo run

Build

cargo check                 # type check, no linking, fastest
cargo build                 # debug build
cargo build --release       # optimized build

# Static binary, runs anywhere, no libc needed
cargo build --release --target x86_64-unknown-linux-musl

Test

cargo test                  # run all tests
cargo test test_name        # run one test
cargo test -- --nocapture   # show println! output
cargo nextest run           # faster runner, one line per test

Format and lint

cargo fmt                   # format all files
cargo fmt -- --check        # check without modifying
cargo clippy                # lint with suggestions
cargo clippy -- -D warnings # treat warnings as errors

Watch mode

bacon                       # recheck on every save
bacon clippy                # relint on every save
bacon test                  # retest on every save
bacon run                   # rerun on every save
cargo watch -x run          # rerun with cargo-watch

Dependencies

cargo add serde --features derive
cargo update                # update the lockfile
cargo tree                  # show the dependency graph
cargo audit                 # check for known vulnerabilities
cargo binstall <crate>      # install a prebuilt cargo tool
cargo doc --open            # build and read your crate docs

Inspect macros

cargo expand                # full crate after macro expansion
cargo expand main           # one module or item

Switch toolchain

cargo +nightly run          # run with nightly
cargo +beta build           # build with beta
rustup show                 # what is installed and active
rustup toolchain list       # all toolchains

Understand an error

rustc --explain E0382       # full write-up for any error code

Terminal shortcuts

c                           # cargo
cb / cr / ct                # cargo build / run / test
cn / cl / cf                # cargo nextest run / clippy / fmt
ll                          # detailed file listing
tree                        # folder tree, respects .gitignore
cat main.rs                 # view a file with syntax highlighting
rg "fn main"                # search code
fd lib.rs                   # find files by name
z hello                     # jump to a recent directory
lg                          # lazygit
top                         # btop system monitor
icons on                    # Nerd Font icons, if your own terminal has the font

Ctrl+R searches history, Ctrl+T picks a file, Alt+C jumps into a subdirectory.

Where things live

The toolchain is installed system wide, so root and laborant share it.

PathContents
/usr/local/rustupToolchains and components
/usr/local/cargoCargo binaries and the crates.io cache
/etc/zsh/playground.zshShared zsh config, aliases and prompt setup
~/.zshrc.localYour own shell additions, loaded after the defaults

Both toolchain directories are writable by any user, so cargo install and cargo add work without sudo.

Every playground includes
Learn more about playgrounds
Start
Settings