thecodex.expert · The Codex Family of Knowledge
Rust

Setup and Cargo

Cargo is Rust’s build tool, package manager, and test runner all in one — the closest thing Rust has to Python’s pip plus a build system.

Rust 1.96 Cargo.toml Last verified:
Canonical Definition

rustup is the official installer and version manager for the Rust toolchain (the compiler rustc, and Cargo). Cargo is Rust’s combined build tool and package manager: it compiles projects, runs tests, manages dependencies declared in Cargo.toml, and publishes packages (called crates) to the central registry, crates.io.

Installing with rustup

rustup is installed via a shell script from rust-lang.org, and manages everything else — including keeping multiple toolchain versions side by side and switching per-project.

Rustterminal
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
$ rustc --version
rustc 1.96.0 (stable)
$ cargo --version
cargo 1.96.0

Creating a project with Cargo

cargo new scaffolds a project with a Cargo.toml manifest and a src/main.rs entry point already wired up; cargo run compiles and runs in one step.

Rustterminal
$ cargo new hello_rust
$ cd hello_rust
$ cargo run
   Compiling hello_rust v0.1.0
    Finished dev [unoptimized + debuginfo] target(s) in 0.42s
     Running `target/debug/hello_rust`
Hello, world!

Cargo.toml and adding dependencies

Dependencies (crates) are declared in Cargo.toml under [dependencies], following semantic versioning; cargo add can add one from the command line directly. Cargo.lock, generated automatically, pins the exact resolved versions for reproducible builds — comparable to go.sum or package-lock.json.

RustCargo.toml
[package]
name = "hello_rust"
version = "0.1.0"
edition = "2024"

[dependencies]
serde = "1.0"
tokio = { version = "1", features = ["full"] }

Sources

1
The Rust Project. The Cargo Book, doc.rust-lang.org/cargo, and the rustup documentation, rust-lang.github.io/rustup.