Cargo, Your Robot Helper
Imagine having a helpful robot that sets up your projects, gathers everything you need, and runs your code for you. In Rust, that robot is called Cargo! π€
Making a new project
To start a fresh project, you type one command in the Terminal. Letβs make one called hello:
cargo new hello
Cargo builds a whole folder for you, all neat and tidy, with a starter program already written inside. That saves you a lot of setup!
Running your project
Now you go into your project and tell Cargo to run it:
cargo run
Cargo builds your code and runs it, all in one step. Hereβs the program Cargo wrote for
you inside the file main.rs β press βΆ Run to see what it does:
Thatβs the same friendly hello you already know β and Cargo set it up for free! π
The little settings file: Cargo.toml
Inside your project, Cargo also makes a file called Cargo.toml. Itβs a tiny settings file that holds your projectβs name and other details.
cargo new to start, and cargo run to build and run. Simple as that! π¦
cargo new hello in the Terminal, then go into the
folder and type cargo run. Watch your robot helper say hello!
Quick quiz
What does the command cargo run do?
That's right! cargo run builds and runs your program in one easy step.
cargo new hello makes a project,
cargo run builds and runs it, and Cargo.toml is the project's
settings file. You've finished World 1 β next world, we start playing with words and numbers! π