Welcome to my collection of small Rust projects! This repository holds various exercises and mini-projects designed to help me practice and solidify my understanding of Rust concepts while reading the book.
These projects are part of my Rust learning journey. Each directory corresponds to a small, self-contained application. They help me practice key Rust concepts as i learn them from the rust book, including:
- Structs
- Methods (with &self vs. &mut self)
- Ownership & Borrowing
- Basic I/O and error handling
- Pattern matching and options
Feel free to explore the projects in any order. Some are simpler than others, but all emphasize struct usage and fundamental Rust knowledge.
Concepts: Structs, methods, ownership, references
Description:
A small program that models a basic library system.
Bookstruct with fields liketitle,author,year_publishedLibrarystruct containing aVec<Book>with methods to add, find, or remove books- Demonstrates how to handle
Option<&Book>orOption<&mut Book>for lookups
Key Files:
Concepts: Structs, traits, methods
Description:
Calculates areas and perimeters/circumferences for shapes.
RectangleandCirclestructs, each with their own fields- Methods to compute area, perimeter, and circumference
- (Optional) An enum
Shapeto hold different shape variants
Key Files:
Concepts: Struct update syntax, mutable references, vector iteration
Description:
A program that tracks items in an inventory.
Itemstruct with fields likename,quantity,priceInventorystruct holding aVec<Item>- Methods to add, update, and calculate the total value of all items
Key Files:
Concepts: Option types, pattern matching, method design
Description:
Stores user profiles in memory, some with optional fields.
Userstruct with fields likeusername,age: Option<u8>,email: Option<String>,active: bool- Methods to update optional fields, check if a profile is complete, and display user data gracefully
Key Files:
src/main.rs
Concepts: Nested structs, summation, references
Description:
Manages a team roster with players and keeps track of total points.
Playerstruct with fields likename,jersey_number,points_scoredTeamstruct holding aVec<Player>- Methods for adding players, summing total points, or finding the highest scorer
Key Files:
src/main.rs
Each project is organized as a separate Cargo package. That means this repo might look like this:
rust-practice-projects/
├── book-library/
│ ├── Cargo.toml
│ └── src/
│ └── main.rs
├── shape-calculator/
│ ├── Cargo.toml
│ └── src/
│ └── main.rs
├── inventory-tracker/
│ ├── Cargo.toml
│ └── src/
│ └── main.rs
├── user-profile-manager/
│ ├── Cargo.toml
│ └── src/
│ └── main.rs
├── team-roster/
│ ├── Cargo.toml
│ └── src/
│ └── main.rs
└── README.md
Alternatively, you could store them all under a single top-level Cargo.toml file with multiple binary targets. For simplicity, I prefer each in its own folder.
-
Install Rust
Make sure you have the Rust toolchain installed. Verify with:rustc --version cargo --version
-
Clone the Repository
git clone https://github.com/MrAbdul/learningRust.git cd rust-practice-projects -
Navigate to a Project
For example, to explore the Book Library System:cd book-library -
Build and Run
cargo run
-
Test (If tests are included)
cargo test
Repeat the above steps for each project directory. Code away and have fun!
I’m using these projects for personal learning, but if you have suggestions, feel free to open an issue or submit a pull request. Constructive criticism and new ideas are always welcome!
This repository is distributed under the MIT License. Feel free to use these exercises as a reference or modify them for your own learning.
Thanks for stopping by! If you see any potential improvements or want to suggest new practice ideas, don’t hesitate to reach out or open an issue.
Keep practicing and enjoy the journey!