The important mental shift is simple:you usually do not compile Rust projects by manually calling rustc. You let Cargo organize the project and drive the compiler for you.
Create the project
In a terminal, run:
cargo new hello-rust cd hello-rust
Cargo creates a new directory named hello-rust and puts a minimal Rust application inside it. By default, cargo new creates a binary project: something that can be run as a program.
What did Cargo create?
hello-rust/
├── Cargo.toml
└── src/
└── main.rsThe main Rust source file for this small executable program.
The project manifest: name, version, Rust edition, and dependencies live here.
Look at the code before running it
The generated program is the classic “Hello, world!” example. RustPrint's equivalent checked example is:
println!("Hello, Rust!");The function named main is where this executable begins. The println! call writes a line of text to standard output. That is enough context for now.
Run it
cargo run
Cargo checks what needs to be built, invokes the Rust compiler, and then runs the resulting program. On the first run you will see build status text followed by the program's own output.
You absolutely can use an editor or IDE button later. Learning cargo run once is still useful because it shows what the editor is doing for you and works everywhere a Rust toolchain is installed.
Three Cargo commands worth recognizing immediately
Build the current binary if needed, then run it.
Check whether the project compiles without producing the final executable, which is often faster.
Compile the project and keep the executable in Cargo's target directory.
Build and run the project's tests when it has some.
What are target/ and Cargo.lock?
After building, Cargo creates a target directory for build output. It can also createCargo.lock, which records exact dependency versions selected for the project. Cargo manages that lock file for you.
None of this is special ceremony you need to master before writing code. It is simply the standard project shape that lets Rust tools agree on where everything is.