Deryks _dev

Full-Stack Web Developer & Technical Leader

<< Back / Reference / Text Editor GUI in Rust

Toolchain Commands

The commands you'll type a hundred times. Print this one.

Daily loop

CommandWhat it does
cargo checkYour default. Type-checks and borrow-checks without producing a binary. Several times faster than build. Use this while fighting the compiler.
cargo runBuilds if needed, then runs. Debug profile — slow binary, fast compile.
cargo run --releaseOptimised. 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 buildCompiles to target/debug/editor without running.
cargo testRuns every #[test] function in the crate.

Code quality — matters for a portfolio repo

CommandWhat it does
cargo fmtFormats every file to the community standard. No configuration, no debate. Run before every commit.
cargo clippy831 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 --fixApplies the mechanical fixes automatically.
cargo doc --openBuilds 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

CommandWhat it does
cargo add crateAdds a dependency to Cargo.toml at the latest compatible version.
cargo add crate --features xAdds it with optional features enabled.
cargo remove crateRemoves it.
cargo updateBumps Cargo.lock within the version ranges in Cargo.toml.
cargo treePrints the full dependency graph. Useful for "why do I have three versions of this?"
Cargo.toml vs Cargo.lockCargo.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

CommandWhat it does
rustup updateUpdates to the latest stable Rust. Safe — Rust takes backwards compatibility seriously.
rustup showWhich toolchains are installed and which is active.
rustup docOpens the entire offline Rust documentation set, including the book.
rustup component add rust-analyzerThe language server — autocomplete, inline types, jump-to-definition in your editor.
source ~/.cargo/envFixes "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