Skip to lesson content
navan✳THE BUILD LABRUST
0/53 complete
BUILD LAB / RUST/ DESIGN, SAFETY & SHIPPING
BUILD NOTE 52 / 53

A build is the start of shipping.

Package a tool with configuration, tests, and an operational contract.

BY NAVAN SAMI◷ 9 MIN READADVANCEDRUST 2024

01 Understand the contract

cargo build --release produces an optimized binary for a selected target. That does not make a binary portable across every operating system, architecture, or C library. A deployable service also needs configuration, health checks, graceful shutdown, logs, and an explicit persistence model. Desktop applications add platform dependencies, bundling, and signing. The cookbook includes local runnable projects and describes the next production decisions beside each one. Review dependency updates and lockfile changes as part of maintaining the application, not just launching it.

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/shipping/src/main.rs
use std::time::Duration;
fn main() {
    let shutdown_budget = Duration::from_secs(10);
    let environment = "local";
    println!(
        "mode={environment}, shutdown={}s",
        shutdown_budget.as_secs()
    );
}
↳ EXPECTED OUTPUT
mode=local, shutdown=10s
  1. 1

    A shutdown budget is an operational policy, not automatic cancellation.

  2. 2

    Use configuration at the application boundary.

  3. 3

    The cookbook shows ctrl_c handling and a local-only default address.

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

03 Mind the boundary

04 Your next build

A SMALL MISSION

Define a small validated configuration type with a nonzero port.

Reveal one possible solution +
solutions/shipping/src/main.rs
struct Config {
    port: u16,
}
fn config(port: u16) -> Result<Config, &'static str> {
    if port == 0 {
        Err("explicit port required")
    } else {
        Ok(Config { port })
    }
}
fn main() {
    assert!(config(0).is_err());
    assert_eq!(config(3000).unwrap().port, 3000);
}

05 Check your reasoning

QUICK SIGNAL CHECK

Does a successful release build establish production readiness?

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.