2.1 The Compilation Process

Like C, Rust is a compiled language. Rust’s compiler (rustc) translates .rs source files into a binary executable. However, Rust also provides Cargo, an integrated build system and package manager that streamlines compilation and project organization.

2.1.1 Cargo: Rust’s Build System and Package Manager

Cargo combines the roles of tools like make or cmake and dependency managers. It handles compilation, manages external libraries (called “crates”), runs tests, and more.

Creating and building a new Rust project:

cargo new my_project
cd my_project
cargo build

Cargo generates a standard directory layout (with src/ for code and Cargo.toml for metadata), which helps manage larger codebases consistently.