Prerequisites
Before you begin, you’ll need to install Rust on your system.- macOS / Linux
- Windows
Install Rust using rustup, the official Rust installer:Follow the on-screen instructions. After installation, restart your terminal or run:
Verify Installation
Check that Rust is installed correctly:If you already have Rust installed, make sure it’s up to date:
rustup updateClone the Repository
Get the Rust Lab code on your machine:Project Structure
The repository contains three learning projects:Run Your First Project
Let’s start with the ownership project to understand Rust’s most distinctive feature.Run the project
Use Cargo to compile and run the code:You’ll see output demonstrating ownership and cloning:
Why This Matters
The ownership project demonstrates Rust’s memory safety without garbage collection:- Line 2-3:
my_nameowns the string “Maysam” - Line 5: Ownership moves to
new_variable - Lines 6-7: Attempting to use
my_namewould cause a compile error - Line 12-15: Using
.clone()creates a copy, allowing both variables to be used
Explore the Other Projects
Data Types Project
Navigate to the data types project and run it:- String types (
&strvsString) - Integer types (signed and unsigned)
- Floating-point numbers
- Characters (including emoji! 🦀)
- Tuples and arrays
- Type parsing
Rock Paper Scissors Game
Try the interactive game:exit to quit the game.
Experiment with the Code
The best way to learn is by modifying the code:Change the Values
Modify strings, numbers, or game messages to see how Rust handles changes
Break Things
Intentionally introduce errors to learn from compiler messages
Add Features
Extend the Rock Paper Scissors game with score tracking or new options
Explore Types
Try different data types in the datatypes project
Essential Commands
Here are the Cargo commands you’ll use frequently:| Command | Description |
|---|---|
cargo run | Compile and run the project |
cargo build | Compile without running |
cargo build --release | Build optimized release version |
cargo check | Check for errors without building |
cargo clean | Remove build artifacts |
Troubleshooting
Rust command not found
Rust command not found
Make sure Rust is in your PATH. Restart your terminal or manually source the environment:
Compilation errors
Compilation errors
Rust’s compiler errors are very descriptive. Read them carefully—they often include suggestions for fixing the issue.If you’re stuck, try copying the error message into a search engine or asking on the Rust Users Forum.
Edition configuration
Edition configuration
The Cargo.toml files specify Make sure your Rust installation is up to date:
edition = "2024". Note that Rust editions are 2015, 2018, and 2021. If you encounter edition-related errors, you may need to update the Cargo.toml to use edition = "2021" (the latest stable edition):Next Steps
Now that you’ve run the projects, dive deeper into the concepts:Ownership Concepts
Deep dive into Rust’s ownership system
Data Types Guide
Comprehensive type system reference
Learning Path
Structured approach to mastering these projects
External Resources
Books, courses, and community links
Remember: the Rust compiler is your friend! Its error messages are designed to teach you. Read them carefully and you’ll learn faster.