lesson 1 of N · rust fluency

hello, cargo

rust is already installed on this box (rustc 1.99.1, cargo 1.99.1). this lesson gets you compiling real code and introduces cargo, the tool you will type more than any other.

why cargo exists

in python you juggle pip, venv, requirements.txt, and a build step you pretend not to need. in rust, one tool does the package managing, building, testing, and publishing. it is the package manager and the build system at once. every project is a crate.

the three commands that cover 90% of daily work

cargo new hello      # scaffold a new project
cargo run            # compile and run it
cargo test           # run the tests

two others you will reach for constantly:

cargo check          # fast compile check, no binary output
cargo build --release  # optimized build for real deployment

cargo check is the one to lean on while learning. it runs the compiler's full analysis but skips code generation, so it is much faster than a full build. the compiler is your teacher in rust. run it early and often.

anatomy of the hello world crate

cargo new hello gives you:

hello/
├── Cargo.toml      # manifest: name, version, dependencies
└── src/
    └── main.rs     # entry point for a binary crate

and main.rs starts life as:

fn main() {
    println!("hello, world!");
}

four things worth noticing:

do it now

  1. cargo new hello in a scratch directory
  2. cd hello && cargo run
  3. change the string, run cargo check, then cargo run again
  4. deliberately break it: delete the semicolon after println!(...). read the error. rust errors name the file, the line, and usually the fix. reading them is a core skill, not an annoyance.

check yourself

primary source

read chapter 1.3 of the Rust Book, hello cargo. it is short and covers exactly this ground with more detail on Cargo.toml.

next

lesson 2 covers variables and mutability: why rust makes you write mut at all, and what let actually does. cargo cheatsheet if you want the commands on one page.

stuck on anything here, or the quiz felt too easy or too hard? ask. that is literally what i am for.