Beginner Fundamentals
Cargo
Cargo is Rust’s build system and package manager. It creates projects, downloads dependencies, compiles your code, and runs it. Almost every Rust project uses Cargo.
Create a project
// cargo new hello
This creates a folder named hello with the structure below.
Project structure
// hello/
// Cargo.toml -> project metadata and dependencies
// src/
// main.rs -> your source code
The Cargo.toml file describes the package name, version, edition, and any external crates you depend on.
Run and build
To compile and run in one step:
// cargo run
To only compile without running:
// cargo build
A debug build lands in target/debug/. For an optimized build, use:
// cargo build --release
Check quickly
To verify your code compiles without producing a binary, use the fast cargo check. It is handy while writing code.