cargo new
| cargo new hello | |
| What cargo creates | |
| cargo run | |
| Debug vs release |
cargo new hello
Cargo is the Rust build tool and project manager in one.
The command below creates a folder named hello with a ready to build binary project inside.
cargo new hello
Created binary (application) 'hello' package
What cargo creates
Every new project starts with the same two entries: a manifest and a source folder.
Cargo.toml holds package metadata and settings, while src/main.rs holds the first lines of code.
ls hello
Cargo.toml src
Open src/main.rs to see a small hello program that the next lesson explains line by line.
cargo run
Move into the project folder and run the program with one command.
Cargo compiles the code first when needed and then starts the resulting binary.
cargo run
Hello, world!
Debug vs release
A plain build is fast to compile and keeps extra checks, so it fits daily work.
Add the release flag for the optimized binary that ships to users.
cargo build
cargo build --release
The first result lands in target/debug and the second in target/release.
Next: Your first program
Article author: Arthur Isaev