Create and run a Cargo project
Quick answer
Cargo creates a project structure, builds Rust code and runs executable programs. Use a new empty workspace directory that you own. The project will contain Cargo.toml, which describes the package, and src/main.rs, which contains the executable's source.
Create, edit, check and run
Use the pinned toolchain installed in the previous lesson. The edition option sets the language edition explicitly. After creation, enter the new directory, replace src/main.rs with the second example, then run cargo +1.85.0 check and cargo +1.85.0 run. check checks the code without producing the final executable; run builds as needed and runs it. Build messages may vary.
cargo +1.85.0 new --edition 2024 library_countercd library_counterManual terminal step; output depends on the environment.
Use a fresh name; do not overwrite an existing project.
Expected stdout (not executed):
Books ready: 8This is the program's stdout after cargo run, separate from Cargo's build messages.
Common mistake
Run Cargo from the package directory or a suitable workspace. If Cargo cannot find Cargo.toml, first verify your working directory.
Try it yourself
Change the displayed book count, run check and then run the program again.
Static examples for Rust 1.85.0, edition 2024. Run them locally in a disposable project; ByteMind execution support and these outputs have not been verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Create and run a Cargo project — practice quiz
Choose one answer per question, then review the explanation.
What is the purpose of Cargo.toml in a new project?
After editing main.rs, which command checks code without producing the final executable?
Cargo cannot find Cargo.toml. What is a useful first check?