<< Back / Reference / Text Editor GUI in Rust
Toolchain Commands
The commands you'll type a hundred times. Print this one.
Daily loop
| Command | What it does |
|---|---|
cargo check | Your default. Type-checks and borrow-checks without producing a binary. Several times faster than build. Use this while fighting the compiler. |
cargo run | Builds if needed, then runs. Debug profile — slow binary, fast compile. |
cargo run --release | Optimised. Slow to compile, ~10–100× faster at runtime. Use only when measuring performance or shipping — a debug-build editor will feel sluggish on big files and that is not a real bug. |
cargo build | Compiles to target/debug/editor without running. |
cargo test | Runs every #[test] function in the crate. |
Code quality — matters for a portfolio repo
| Command | What it does |
|---|---|
cargo fmt | Formats every file to the community standard. No configuration, no debate. Run before every commit. |
cargo clippy | 831 lints for non-idiomatic Rust. This is the closest thing to having a senior Rust dev review your code, and a reviewer will notice if you haven't run it. |
cargo clippy --fix | Applies the mechanical fixes automatically. |
cargo doc --open | Builds docs for your crate and every dependency, at the exact versions you're using, then opens them. Offline and always correct — better than docs.rs. |
Dependencies
| Command | What it does |
|---|---|
cargo add crate | Adds a dependency to Cargo.toml at the latest compatible version. |
cargo add crate --features x | Adds it with optional features enabled. |
cargo remove crate | Removes it. |
cargo update | Bumps Cargo.lock within the version ranges in Cargo.toml. |
cargo tree | Prints the full dependency graph. Useful for "why do I have three versions of this?" |
Cargo.toml vs Cargo.lock
Cargo.toml is what you asked for (eframe = "0.36.1", meaning "0.36.1 or any compatible later version"). Cargo.lock is what yougot — exact versions of all 414 crates. Commit both for a binary; the lockfile is what makes a reviewer's cargo run reproduce your build exactly.rustup — managing Rust itself
| Command | What it does |
|---|---|
rustup update | Updates to the latest stable Rust. Safe — Rust takes backwards compatibility seriously. |
rustup show | Which toolchains are installed and which is active. |
rustup doc | Opens the entire offline Rust documentation set, including the book. |
rustup component add rust-analyzer | The language server — autocomplete, inline types, jump-to-definition in your editor. |
source ~/.cargo/env | Fixes "command not found: cargo" in a shell that didn't pick up the PATH. |
This machine specificallyFedora-based atomic desktop. Rust lives in
~/.cargo and~/.rustup, installed by rustup. Do notrpm-ostree install rust — layering a toolchain onto the base image gets you an older compiler and a rebase headache. rustup in $HOME is the right answer here, and it uninstalls cleanly with rustup self uninstall.Reading a compiler error
Rust errors have a fixed shape. Learn it once and they stop being walls of text:
error[E0502]: cannot borrow `self.text` as mutable ...
--> src/main.rs:22:17 <- file:line:column
|
22 | ui.add(TextEdit::multiline(&mut self.text))
| ^^^^^^^^^^^^^^ <- the exact span
|
= help: consider changing this to be mutable <- usually correct- Read the last line first. The
help:ornote:at the bottom is frequently the literal fix. - Fix the first error only, then re-check. One real error often cascades into ten fake ones.
rustc --explain E0502gives a full page on any error code, with examples. There is one for every code.