Rust
Tools
rustup: rust installer and update managerrustc: rust compilercargo: rust build system and package managercargo clippy: rust code lintercargo fmt: rust code formatter
Directories
~/.rustup: rustup metadata and toolchains~/.cargo: cargo home directory~/.cargo/bin: rust commands directory
Configuration
Add rust tools bin directory to shell path
~/.cargo/binHelp Docs
Open local rust docs
rustup docRust Compiler
Compile rust file
rustc <file>Run compiled file
./<file>
source <file>Rustup
Show current configured version and check for available updates
rustup show
rustup checkUpdate rust toolchains and rustup
rustup updateCargo
Show cargo version
cargo --versionCreate new cargo project
cargo new <project-name>Add dependency (then install dependency via cargo build)
cargo add <dependency>Update cargo crate dependencies to latest semver minor release versions (major version bumps require editing cargo.toml)
cargo updateCheck package and dependencies for errors
cargo checkBuild project (--release or -r for release mode with build optimisations)
cargo build
cargo build --releaseExecute generated binary to run debug or release build app
./target/debug/<app-binary>
./target/release/<app-binary>Build and run project (in single step)
cargo runRun tests and benchmarking
cargo test
cargo benchDocument project (creates local docs for project and all dependencies)
cargo doc
cargo doc --openPublish library to crates.io
cargo publishVS Code
Extension: rust-analyzer
Format code: SHIFT + OPTION + F (can also be configured to format on save / paste)
Clippy
Run clippy (rust linter) on project
cargo clippyAutomatically fix linter issues that have known resolutions
cargo fixLast updated