Skip to content
KodeTrail

Camp 1 · Step 2 of 12

Hello, Cargo!

Meet Cargo, the build tool other languages envy, and dissect Rust's Hello World.

12 min+50 XP

Most languages bolt on a package manager years later. Rust shipped with Cargo from day one — builder, test runner, dependency manager, and project scaffolder in one command.

The Cargo workflow

On a real machine, a Rust project starts and runs like this:

cargo new hello_trail    # scaffold a project
cd hello_trail
cargo run                # compile + run in one step

cargo new creates a Cargo.toml (the project manifest) and src/main.rs:

hello_trail/
├── Cargo.toml      ← name, version, dependencies
└── src/
    └── main.rs     ← your code

Dependencies ("crates", from the community registry crates.io) are one line in Cargo.toml — Cargo fetches, builds, and version-locks them. (Our playgrounds compile in the cloud, so you can focus on the language.)

Dissecting main.rs

RustCloud run
  • fn main() — functions start with fn; main is the entry point
  • println! — the ! marks a macro (code that writes code — a later adventure; for printing, just include it)
  • {} placeholders fill left-to-right with the arguments

Statements end in ;, blocks live in { } — familiar territory if you've seen any C-family language.

Checkpoint

What is Cargo?

Checkpoint

Why does println! end with an exclamation mark?

What's next

Variables — and Rust's surprising default that they can't change unless you say so.