cargo new

Contents
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

Related articles
Rust
Rust course: zero to hero in 50 lessons
What is Rust and where it runs
Install Rust
cargo new
Your first program
Variables
Numbers
Strings
Booleans
Tuples
Arrays
Vectors
Slices
if and else
match
Loops
Ownership
Borrowing
Lifetimes
Functions
Structs
Enums in Rust
Advanced match in Rust
Option combinators in Rust
Result and the question mark in Rust
Advanced strings in Rust
Vec methods in Rust
HashMaps in Rust
Modules in Rust
Crates and workspaces in Rust
Testing in Rust
Error handling
Traits
Generics
Trait bounds
Closures
Iterators
Smart pointers
Threads
Mutex and Arc
Files
CLI arguments
Environment variables
Diagnostics
Time
Parsing strings
TCP networking
Capstone: wordfreq CLI
Capstone: tiny HTTP server
Modern Rust tour
Hero roadmap: the whole course on one page
Install Rust on Windows 11
Install Rust on Ubuntu
Install Rust on Rocky Linux
Install Rust on macOS
Install Rust on FreeBSD
Rust in Docker

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: