This repository contains solutions to various exercises I completed while reading The Rust Programming Language book. The exercises cover a wide range of Rust concepts, from basic syntax to advanced features. The purpose of this repository is to document my learning journey and provide solutions that may help others understand the key topics discussed in the book.
The Rust Programming Language, often referred to as The Book in the Rust community, is a comprehensive guide to learning the Rust programming language. This repository contains my solutions and code samples for the exercises in the book. Each section focuses on different aspects of the language, allowing you to follow along with my progress and try the exercises yourself.
Before you begin, ensure you have the following installed:
- Rust: Install the latest stable version of Rust from rust-lang.org
- Cargo: The Rust package manager, which comes bundled with Rust.
You can verify your installation by running the following commands in your terminal:
rustc --version
cargo --version
The repository is organized by exercises from the book. Each chapter contains exercises, and each exercise is in its own directory.
├── 01_hello_world/
│ └── main.rs
├── 01_hello_cargo/
│ ├── src/
│ │ └── main.rs
│ ├── Cargo.lock
│ └── Cargo.toml
├── ...
├── LICENSE
└── README.md
- Each folder corresponds to an exercise.
- Each Rust source file (
.rs
) represents an exercise solution. - Exercise naming pattern is
{chapter_number}_{exercise_shortname}/
Feel free to browse the chapters and exercises to see how I approached the problems.
To run the exercises, follow these steps:
-
Clone the repository:
git clone https://github.com/ozefe/rust-exercises.git cd rust-exercises
-
Navigate to the exercise you want to run. For example:
cd 01_hello_cargo
-
Compile and run the code using Cargo:
cargo run
Or if you’re working directly with
.rs
files:rustc main.rs ./main
Each exercise is self-contained and can be compiled and run individually.
The exercises in this repository touch upon a wide range of Rust topics, including but not limited to:
- Variables and Mutability
- Data Types
- Functions
- Control Flow (
if
, loops, etc.) - Ownership, Borrowing, and Lifetimes
struct
s andenum
s- Pattern Matching
- Error Handling (
Result
,Option
) - Modules and Crates
trait
s and Generics- Smart Pointers
- Concurrency
Each exercise is designed to reinforce the concepts explained in the corresponding chapter of The Rust Programming Language.
If you find any bugs in the solutions, or if you want to propose improvements, feel free to submit an issue or a pull request. Contributions are always welcome!
- Fork the repository
- Create a new branch (
git checkout -b feature-branch
) - Make your changes
- Commit your changes (
git commit -m "Add feature"
) - Push to the branch (
git push origin feature-branch
) - Open a pull request
This repository is licensed under the MIT License. See the LICENSE file for more information.