Skip to chapter content
navan✳THE BUILD LABRUST / GUIDE
0/26 read
CHAPTER 01 / 21 · THE LANGUAGE

What Rust checks.

See the compiler, Cargo, and the promises a successful build actually makes.

BY NAVAN SAMILONG READRUST 2024THEORY FIRST
01 / THE MENTAL MODEL

The idea behind the syntax.

Rust is a compiled language: source code becomes an executable after a compiler checks its syntax, types, and a set of ownership rules. Those checks happen before the program runs. They can reject a reference that might outlive its data, but they cannot know whether your invoice calculation is correct. The useful mental model is a partnership: the compiler enforces language contracts; you still define the product's meaning.

A Rust package is described by Cargo.toml and contains source under src. Cargo resolves dependencies and orchestrates checking, compiling, running, and testing. The compiler rustc performs the language checks. This division matters when you read an error: a manifest or dependency problem is different from a type or borrow error in the source. The 2024 edition selects a set of language rules and idioms; it is declared in the manifest rather than implied by the date on your machine.

02 / THE RULES

What Rust is checking.

A binary crate has a main function as its entry point. A library crate exposes functions and types to callers. A macro call such as println! has an exclamation mark because it expands syntax before ordinary compilation continues; it is not a regular function call. In a simple program, statements inside main execute in order and values leave scope at the closing brace.

A clean build is evidence that the program obeys the compiler's rules. It is not proof of useful behavior, reliable input handling, or a stable public API. Read a code example by asking what each binding owns, what each function returns, and which assumptions the type system can check. That habit will make later concepts such as borrowing and concurrency feel like extensions of one model rather than separate tricks.

03 / CODE, EXPLAINED

See the rule in context.

Each example isolates one part of the model. Follow the bindings, types, ownership transfers, and possible outcomes line by line.

EXAMPLE 01

Rust, rustc & Cargo

Rust compiles source into a native executable. The compiler checks types and borrowing before your program runs; it cannot decide whether your product requirements are correct. rustc is the compiler. Cargo manages packages, builds, tests, and dependencies. Start with a small program you can explain, then use cargo check for fast feedback. A package created with cargo new has a Cargo.toml manifest and a src/main.rs binary entry point. In this course, each foundation example is complete and uses only the standard library; the cookbook introduces ecosystem crates in real projects.

welcome.rs
fn main() {
    let project = "Build Lab";
    println!("Hello, {project}!");
    println!("Next: change one thing, then rebuild.");
}
OUTPUT
Hello, Build Lab!
Next: change one thing, then rebuild.
  1. main is the entry point for this binary.
  2. println! is a macro; the exclamation mark is part of its name.
  3. Build the workbook crate with cargo run -p lesson_welcome, or compile this file with rustc --edition 2024 main.rs.

The boundary: A successful compile is evidence of language-rule compliance, not a proof that the program meets its specification.

EXAMPLE 02

Cargo manifests & dependencies

Cargo.toml declares package metadata, an edition, and dependencies. Cargo.lock records resolved dependency versions for reproducibility and should be committed for these executable workbook projects. An edition selects language rules and migration boundaries; it is not the compiler version. cargo check type-checks without a final executable, cargo test runs tests, cargo fmt formats, and cargo clippy offers additional diagnostics. Features are additive configuration switches: inspect which optional capabilities a dependency enables instead of adding every feature by default.

cargo-workflow.rs
fn main() {
    let manifest = "[package]\nname = \"first-build\"\nversion = \"0.1.0\"\nedition = \"2024\"\n";
    println!(
        "{}",
        manifest
            .lines()
            .find(|line| line.starts_with("edition"))
            .unwrap()
    );
}
OUTPUT
edition = "2024"
  1. A manifest is configuration rather than Rust source.
  2. The workbook generates a proper manifest per lesson.
  3. Run cargo check, cargo test, and cargo fmt --check from the workspace root as appropriate.

The boundary: A semver requirement such as 1 allows compatible updates. A committed lockfile pins the actual resolved graph until updated.

04 / THE CONNECTION

Keep this model.

Rust's checks are strongest when the program's contracts are expressed in its types and ownership relationships. Tests and review still establish whether the contract is the right one.

Finished reading?
Built with curiosity. By Navan Sami. ↗Rust · The rules behind the code.