A beginner-friendly Rust project to learn the basics of Rust programming language and Cargo package manager.
- About
- Prerequisites
- Installation
- Quick Start
- Project Structure
- Available Commands
- Learning Resources
- Next Steps
This project is a starting point for learning Rust basics. It includes a simple "Hello, world!" program to verify your Rust and Cargo installation, and serves as a foundation for exploring Rust concepts like variables, functions, ownership, pattern matching, and more.
Before you begin, make sure you have the following installed:
- Rust - The Rust programming language
- Cargo - Rust's package manager and build system (comes with Rust)
The easiest way to install Rust and Cargo is using rustup:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shAfter installation, restart your terminal and verify the installation:
rustc --version
cargo --versionTo build and run the default "Hello, world!" program:
cargo runYou should see:
Hello, world!
To compile the project without running it:
cargo buildThis creates a debug executable in target/debug/.
To create an optimized release build:
cargo build --releaseThis creates a release executable in target/release/ with optimizations enabled.
hello-rust/
├── Cargo.toml # Project manifest (package info, dependencies)
├── src/
│ └── main.rs # Main entry point of the program
└── target/ # Build artifacts (auto-generated)
├── debug/ # Debug builds
└── release/ # Release builds
This file contains your project's configuration:
- [package] - Metadata about your project (name, version, edition)
- [dependencies] - External packages your project depends on
- [dev-dependencies] - Dependencies only used for development
The entry point of your Rust program. The main() function is where your program starts executing.
| Command | Description |
|---|---|
cargo run |
Compile and run the project |
cargo build |
Compile the project in debug mode |
cargo build --release |
Compile the project with optimizations |
cargo check |
Check if the project compiles without building |
cargo test |
Run tests |
cargo fmt |
Format code according to Rust style guidelines |
cargo clippy |
Lint your code for common mistakes and improvements |
cargo clean |
Remove the target directory |
cargo doc --open |
Generate and open local documentation |
- The Rust Programming Language Book - The official and comprehensive guide to Rust
- Rust by Example - Learn Rust through practical examples
- The Cargo Book - Complete guide to Cargo
- Rustlings - Small exercises to get you used to reading and writing Rust code
- Exercism - Rust Track - Curated programming exercises with mentor feedback
- Rust Forum - Ask questions and discuss Rust
- Reddit - r/rust - Rust community discussions
- Rust Discord Server - Chat with Rust developers in real-time
Here are some ideas to expand your learning:
-
Add More Functions - Create and call additional functions in
main.rsfn greet(name: &str) { println!("Hello, {}!", name); }
-
Work with Variables - Learn about immutability and ownership
let x = 5; let mut y = 10; y += x;
-
Create Modules - Organize code into separate modules
- Create a new file in
src/and usemoddeclarations
- Create a new file in
-
Add Dependencies - Explore external crates from crates.io
- Edit
Cargo.tomlto add a dependency - Example:
serde = "1.0"for serialization
- Edit
-
Write Tests - Learn Rust's testing framework
#[cfg(test)] mod tests { #[test] fn it_works() { assert_eq!(2 + 2, 4); } }
-
Build a Larger Project - Structure your code into libraries and binaries
- Use
cargo checkfrequently during development - it's faster than a full build - Read compiler errors carefully - Rust's error messages are extremely helpful
- Use
rustfmtto automatically format your code:cargo fmt - Use
clippyto catch common mistakes:cargo clippy - Check the official docs - The standard library documentation is comprehensive and searchable
This project is open source and available under the MIT License.
Happy learning! 🦀 Welcome to the Rust community!