Rust
Install Rust using rustup, manage toolchains, and verify cargo for local development before deploying to Discloud.
🧾 Overview
Rust provides performance, memory safety, and predictable resource usage for APIs, workers, and bots. Install with rustup to manage toolchains locally before deploying.
📥 Installation (choose your OS)
Install via rustup script:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.cargo/env
rustc --version
cargo --versionAdd Build Essentials (Debian/Ubuntu)
sudo apt update
sudo apt install -y build-essential pkg-config libssl-devUpdate
rustup updateRemove Toolchain
rustup self uninstallInstall with rustup:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.cargo/env
rustc --version
cargo --versionAdd build tools (if not present):
xcode-select --install # prompts for developer toolsUpdate:
rustup update🧰 Toolchains & Components
1
List installed
rustup toolchain list2
Add nightly (optional)
rustup toolchain install nightly3
Set default
rustup default stable4
Add components (example)
rustup component add clippy rustfmt🗂 Project Init
Create new project:
cargo new myapp
cd myapp
cargo buildRun:
cargo runFormat & lint:
cargo fmt -- --check
cargo clippy -- -D warnings🗃 Common Cargo Commands
cargo new api-service # create binary project
cargo build --release # optimized build
cargo run # build + run
cargo test # run tests
cargo update # update dependency lock
cargo tree # dependency graph (requires cargo-tree)
cargo doc --open # build docs locallyInstall cargo tree (if missing):
cargo install cargo-tree📦 Dependency Management
Dependencies declared in Cargo.toml under [dependencies]:
[dependencies]
reqwest = { version = "0.12", features = ["json"] }
serde = { version = "1", features = ["derive"] }
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }Update lockfile:
cargo update🔄 Updating
rustup update # update all toolchains
rustup self update # update rustup itselfLast updated