Originally published on php2rust.dev — part of the PHP to Rust course. View this lesson on the original site.

Cargo provides built-in commands for common development tasks:

1. Creating a new project

cargo new my_project

This creates a project folder with Cargo.toml (dependencies and metadata) and a src directory for your code.

2. Building and running

cargo build   # Compiles the project (debug mode)
cargo run     # Compiles and runs the project

For faster, optimized builds (e.g. for production):

cargo build --release

3. Managing dependencies

cargo add serde

This updates Cargo.toml and downloads the crate. External libraries in Rust are called crates.

4. Running tests

cargo test

Runs all test functions in the project.

5. Checking code

cargo check

Faster than cargo build, validates code without producing an executable. Useful for quick feedback while coding.

What's next

Next: Stable versus Nightly Rust.

From PHP to Rust — Getting Started with Rust