Skip to lesson content
navan✳THE BUILD LABRUST
0/53 complete
BUILD LAB / RUST/ PACKAGES, FILES & TOOLS
BUILD NOTE 31 / 53

Make the build repeatable.

Understand packages, editions, lockfiles, features, and common commands.

BY NAVAN SAMI◷ 7 MIN READFOUNDATIONSRUST 2024

01 Understand the contract

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.

02 Make it concrete

This is a complete standard-library example. Use Rust stable with the 2024 edition. Run it locally using the Rust workbench.

lessons/cargo-workflow/src/main.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()
    );
}
↳ EXPECTED OUTPUT
edition = "2024"
  1. 1

    A manifest is configuration rather than Rust source.

  2. 2

    The workbook generates a proper manifest per lesson.

  3. 3

    Run cargo check, cargo test, and cargo fmt --check from the workspace root as appropriate.

From the extracted rust-workbench folder
cargo run -p lesson_cargo_workflow

03 Mind the boundary

04 Your next build

A SMALL MISSION

Write a function accepting a small list of enabled feature names and checking for one required feature.

Reveal one possible solution +
solutions/cargo-workflow/src/main.rs
fn enabled(features: &[&str], name: &str) -> bool {
    features.contains(&name)
}
fn main() {
    assert!(enabled(&["json", "tls"], "tls"));
    assert!(!enabled(&[], "tls"));
}

05 Check your reasoning

QUICK SIGNAL CHECK

Does edition = "2024" select a precise compiler version?

ONE MORE CONTRACT YOU CAN EXPLAIN.

Understand it.
Then make it yours.

Run the example, try your own input, and explain the boundary. Log the lesson when the idea makes sense.

Built with curiosity. By Navan Sami. ↗Rust · Make the contract clear. Then build.