├── .editorconfig ├── .gitignore ├── .vscode └── settings.json ├── CONTRIBUTION.md ├── LICENSE ├── README.md ├── resources.md ├── week-1 ├── Day-1.md ├── README.md ├── day-2.md ├── day-3.md ├── day-4.md ├── day-5.md ├── day-6.md ├── day-7.md ├── day2code.rs ├── day3code.rs ├── day4code.rs ├── day5code.rs ├── day6project.rs └── day7code.rs ├── week-2 ├── README.md ├── day-8.md └── day8code.rs ├── week-3 └── README.md ├── week-4 └── README.md ├── week-5 └── README.md ├── week-6 └── README.md └── week-7 └── README.md /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps maintain consistent coding styles across editors 2 | # More info: https://editorconfig.org/ 3 | 4 | root = true 5 | 6 | [*] 7 | indent_style = space 8 | indent_size = 4 9 | end_of_line = lf 10 | charset = utf-8 11 | trim_trailing_whitespace = true 12 | insert_final_newline = true 13 | max_line_length = 80 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | debug/ 4 | target/ 5 | 6 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 7 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 8 | Cargo.lock 9 | 10 | # These are backup files generated by rustfmt 11 | **/*.rs.bk 12 | 13 | # MSVC Windows builds of rustc generate these, which store debugging information 14 | *.pdb 15 | *.exe 16 | 17 | # RustRover 18 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 19 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 20 | # and can be added to the global gitignore or merged into this file. For a more nuclear 21 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 22 | #.idea/ 23 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true, 3 | "editor.rulers": [80], 4 | "[rust]": { 5 | "editor.defaultFormatter": "rust-lang.rust-analyzer", 6 | "editor.formatOnSave": true 7 | }, 8 | "files.trimTrailingWhitespace": true, 9 | "files.insertFinalNewline": true 10 | } 11 | -------------------------------------------------------------------------------- /CONTRIBUTION.md: -------------------------------------------------------------------------------- 1 | # Contribution Guidelines 2 | 3 | Thank you for considering contributing to this project! We welcome all kinds of contributions, from bug reports and documentation improvements to feature requests and code contributions. 4 | 5 | ## How to Contribute 6 | 7 | ### 1. Fork the Repository 8 | - Fork this repository by clicking the "Fork" button at the top right of this page. 9 | - Clone your fork locally: 10 | 11 | ``` 12 | git clone https://github.com/your-username/repository-name.git 13 | 14 | ``` 15 | 16 | ### 2. Create a New Branch 17 | - Create a new branch for your contribution: 18 | 19 | ```bash 20 | git checkout -b my-new-feature 21 | ``` 22 | 23 | ### 3. Make Changes 24 | - Implement your changes, following best practices and keeping the code clean. 25 | - Write or update tests as necessary to ensure your changes are stable. 26 | 27 | ### 4. Commit Your Changes 28 | - Add your changes to the staging area: 29 | 30 | ```bash 31 | git add . 32 | ``` 33 | 34 | - Commit with a meaningful message: 35 | 36 | ```bash 37 | git commit -m "Add feature X" 38 | ``` 39 | 40 | ### 5. Push Changes to Your Fork 41 | - Push your branch to your forked repository: 42 | 43 | ```bash 44 | git push origin my-new-feature 45 | ``` 46 | 47 | ### 6. Submit a Pull Request 48 | - Open a Pull Request (PR) to the main repository: 49 | - Navigate to the original repository and click on the "Pull Requests" tab. 50 | - Click on "New Pull Request" and select the branch you want to merge. 51 | - Provide a clear title and description for your PR, explaining your changes. 52 | 53 | ### 7. Code Review Process 54 | - A project maintainer will review your changes and may request modifications. 55 | - Please be patient, as reviewing PRs may take some time. 56 | - Once your PR is approved, it will be merged into the main branch. 57 | 58 | ## Guidelines for Contributions 59 | 60 | - **Follow coding standards:** Ensure your code follows the style and conventions of the project. 61 | - **Keep commits focused:** Each commit should represent a single, focused change. 62 | - **Update documentation:** If your changes affect usage or add new features, please update the corresponding documentation. 63 | - **Write tests:** Add unit tests and ensure that all tests pass before submitting your PR. 64 | 65 | ## Reporting Bugs 66 | If you find a bug, please create an issue in the repository. Include as much detail as possible: 67 | - A clear and concise description of the bug. 68 | - Steps to reproduce the issue. 69 | - Expected vs. actual behavior. 70 | - Any relevant logs, error messages, or screenshots. 71 | 72 | ## Feature Requests 73 | If you have an idea for a new feature or improvement, feel free to open an issue. Please provide: 74 | - A detailed description of the feature and its use case. 75 | - Any potential benefits or examples of how it will be used. 76 | 77 | 78 | By contributing, you agree that your contributions will be licensed under the same license as the project. 79 | 80 | Thank you for helping improve this project! -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 MORDECAI ETUKUDO 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 50-DaysOfRust Challenge 2 | 3 | A structured 50-day Rust learning and project challenge starting Hacktober 1st. This plan balances learning core concepts and building practical Rust projects. 4 | 5 | ## Week 1: Rust Basics & Syntax 6 | 7 | **Day 1-5:** 8 | - Install Rust and set up the development environment. 9 | - Learn basic syntax: variables, data types, functions, conditionals, loops. 10 | - **Project:** Create a simple CLI calculator to practice basic operations and user input. 11 | 12 | **Day 6-7:** 13 | - Dive into ownership, borrowing, and lifetimes. 14 | - **Project:** Extend your calculator to handle complex operations and introduce error handling. 15 | 16 | ## Week 2: Structs, Enums, and Error Handling 17 | 18 | **Day 8-9:** 19 | - Learn about structs and enums. 20 | - **Project:** Build a small inventory management system using structs and enums. 21 | 22 | **Day 10-11:** 23 | - Understand pattern matching and control flow. 24 | - **Project:** Add pattern matching to the inventory system, allowing for item categorization. 25 | 26 | **Day 12-14:** 27 | - Deep dive into Rust's error handling with `Result` and `Option`. 28 | - **Project:** Add error handling to the inventory, making it more robust. 29 | 30 | ## Week 3: Collections and Iterators 31 | 32 | **Day 15-17:** 33 | - Learn about vectors, hash maps, and strings. 34 | - **Project:** Build a contact book app, allowing for the addition, removal, and search of contacts. 35 | 36 | **Day 18-19:** 37 | - Master iterators and closures. 38 | - **Project:** Add sorting and filtering options to the contact book using iterators. 39 | 40 | **Day 20-21:** 41 | - Study traits and generics in Rust. 42 | - **Project:** Refactor the contact book to make it more generic and reusable. 43 | 44 | ## Week 4: Async Programming and Concurrency 45 | 46 | **Day 22-25:** 47 | - Learn async programming with `tokio`. 48 | - **Project:** Build an asynchronous web scraper that fetches and processes data from multiple websites concurrently. 49 | 50 | **Day 26-28:** 51 | - Study concurrency using threads. 52 | - **Project:** Modify the web scraper to handle multiple scraping tasks concurrently. 53 | 54 | ## Week 5: Working with Files, Crates, and Modules 55 | 56 | **Day 29-31:** 57 | - Learn file I/O in Rust and how to use crates. 58 | - **Project:** Build a log parser that reads logs from a file and generates a report. 59 | 60 | **Day 32-34:** 61 | - Learn about Rust modules and crate structures. 62 | - **Project:** Refactor the log parser to be modular and scalable. 63 | 64 | ## Week 6: Web Development with Actix or Warp 65 | 66 | **Day 35-38:** 67 | - Study basic web development in Rust using `actix-web` or `warp`. 68 | - **Project:** Create a simple REST API for a TODO app. 69 | 70 | **Day 39-41:** 71 | - Add database integration with `SQLx` or `Diesel`. 72 | - **Project:** Extend the TODO app to store tasks in a Postgres or SQLite database. 73 | 74 | ## Week 7: Advanced Topics (FFI, Unsafe, Macros) 75 | 76 | **Day 42-44:** 77 | - Learn about Foreign Function Interface (FFI) and using C libraries in Rust. 78 | - **Project:** Build a small Rust application that uses a C library for some functionality. 79 | 80 | **Day 45-47:** 81 | - Dive into unsafe Rust. 82 | - **Project:** Build a memory-efficient data structure using unsafe code for performance optimization. 83 | 84 | **Day 48-50:** 85 | - Study Rust macros and how to create your own. 86 | - **Project:** Create a custom derive macro to automatically generate code for common tasks in one of your previous projects. 87 | 88 | ### Don't forget to drop a star to the repository 89 | 90 | Throughout the challenge, contribute to Hacktoberfest by submitting pull requests to open-source Rust projects or libraries. 91 | -------------------------------------------------------------------------------- /resources.md: -------------------------------------------------------------------------------- 1 | # Resources 2 | 3 | A list of valuable resources for learning Rust and enhancing your project development skills. 4 | 5 | ## resources bank 6 | this is a list of resources all unofficial resources but helpfull you can select from the list 7 | - [Rust Resources Bank](https://github.com/ImplFerris/LearnRust) – The official Rust website. 8 | 9 | ## Official Documentation 10 | - [Rust Programming Language](https://www.rust-lang.org) – The official Rust website. 11 | - [The Rust Book](https://doc.rust-lang.org/book/) – Comprehensive guide for learning Rust from the ground up. 12 | - [Rust by Example](https://doc.rust-lang.org/rust-by-example/) – Learn Rust by going through examples. 13 | 14 | ## Learning Platforms 15 | - [Exercism.io](https://exercism.io/tracks/rust) – Offers Rust exercises for improving your skills through practice. 16 | - [Rustlings](https://github.com/rust-lang/rustlings) – A collection of small exercises to get you familiar with Rust. 17 | - [Rust Videos on YouTube](https://www.youtube.com/results?search_query=rust+programming) – Watch tutorials and conferences to gain a deeper understanding. 18 | 19 | ## Asynchronous Programming 20 | - [Async in Rust](https://rust-lang.github.io/async-book/) – Learn about asynchronous programming in Rust using `async` and `await`. 21 | - [Tokio](https://tokio.rs/) – A runtime for writing reliable, asynchronous applications with Rust. 22 | 23 | ## Web Development in Rust 24 | - [Actix Web](https://actix.rs/) – A powerful, pragmatic, and extremely fast web framework for Rust. 25 | - [Warp](https://github.com/seanmonstar/warp) – A super-easy, composable web framework for building HTTP APIs. 26 | 27 | ## Crate Management 28 | - [crates.io](https://crates.io) – The Rust community’s crate registry, where you can find libraries for various needs. 29 | 30 | ## IDEs & Tools 31 | - [Rust Analyzer](https://rust-analyzer.github.io/) – A fast, modern IDE support for Rust, with features like code navigation and inline error detection. 32 | - [VSCode Rust Extension](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) – Add Rust support to Visual Studio Code for enhanced development. 33 | 34 | ## Contributing to Open Source 35 | - [Rust GitHub](https://github.com/rust-lang) – Explore Rust-related open-source projects on GitHub and contribute to the community. 36 | 37 | ## Community & Forums 38 | - [Rust Users Forum](https://users.rust-lang.org/) – Ask questions and engage with the Rust community. 39 | 40 | -------------------------------------------------------------------------------- /week-1/Day-1.md: -------------------------------------------------------------------------------- 1 | # Installing Rust and Setting Up Your Development Environment 2 | 3 | Follow these steps to install Rust and set up your development environment. For more information on installing Rust and setting up your development environment see https://www.rust-lang.org/tools/install and https://www.youtube.com/watch?v=vo9sMyiqaY0&list=PLDi2liHqCnVp0oM9rNp1Hy_H5aL6QUybN for video tutorials on how to install Rust and setting up your development environment 4 | 5 | ## Step 1: Install Rust 6 | The easiest way to install Rust is by using **rustup**, the Rust toolchain installer. It installs Rust and the required tools. 7 | 8 | 1. Open a terminal and run the following command to install Rust: 9 | 10 | ```bash 11 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh 12 | ``` 13 | 14 | 2. Follow the on-screen instructions to complete the installation. Once done, the installer will set up your environment and install the `cargo` command, which is Rust's package manager. 15 | 16 | ## Step 2: Update Your Path (if necessary) 17 | After installation, ensure that Rust's binaries are available in your shell. The installer will attempt to update your PATH automatically, but if it didn’t succeed, you may need to add it manually. 18 | 19 | - Add this line to your shell profile (e.g., `.bashrc`, `.zshrc`, or `.bash_profile`): 20 | 21 | ```bash 22 | export PATH="$HOME/.cargo/bin:$PATH" 23 | ``` 24 | 25 | 3. Source your shell configuration or restart the terminal for the changes to take effect. 26 | 27 | ```bash 28 | source ~/.bashrc # or source ~/.zshrc 29 | ``` 30 | 31 | ## Step 3: Verify Installation 32 | To verify Rust is correctly installed, run the following commands: 33 | 34 | ```bash 35 | rustc --version 36 | cargo --version 37 | ``` 38 | 39 | These commands should print out the installed versions of Rust and Cargo. 40 | 41 | ## Step 4: Set Up a Code Editor 42 | 43 | 1. **Visual Studio Code**: 44 | - Install the **Rust Analyzer** extension from the VS Code marketplace for autocompletion, error checking, and more. 45 | - Set up the **rustfmt** extension for automatic code formatting. 46 | 47 | 2. **JetBrains CLion/IntelliJ IDEA**: 48 | - Install the **Rust** plugin for code suggestions and management. 49 | 50 | ## Step 5: Test Your Setup 51 | 52 | Create and run a simple Rust project to ensure your setup is working. 53 | 54 | 1. Create a new Rust project: 55 | 56 | ```bash 57 | cargo new hello_rust 58 | cd hello_rust 59 | ``` 60 | 61 | 2. Build and run the project: 62 | 63 | ```bash 64 | cargo run 65 | ``` 66 | 67 | This should output: 68 | 69 | ```bash 70 | Hello, world! 71 | ``` 72 | 73 | You're now ready to start coding in Rust! 🚀 74 | ``` -------------------------------------------------------------------------------- /week-1/README.md: -------------------------------------------------------------------------------- 1 | ## Week 1: Rust Basics & Syntax 2 | 3 | **Day 1-5:** 4 | - Install Rust and set up the development environment. 5 | - Learn basic syntax: variables, data types, functions, conditionals, loops. 6 | - **Project:** Create a simple CLI calculator to practice basic operations and user input. 7 | 8 | **Day 6-7:** 9 | - Dive into ownership, borrowing, and lifetimes. 10 | - **Project:** Extend your calculator to handle complex operations and introduce error handling. 11 | -------------------------------------------------------------------------------- /week-1/day-2.md: -------------------------------------------------------------------------------- 1 | # variables in Rust 2 | for video explain vist https://www.youtube.com/watch?v=J3fv1-1SgI4&list=PLDi2liHqCnVp0oM9rNp1Hy_H5aL6QUybN&index=4 3 | 4 | 5 | In Rust, a variable is like a container that holds some kind of value, and you can give it a name so you can easily refer to it later. However, unlike some other languages, Rust variables are **immutable** by default, which means once you put something in that "box," you can't change it unless you specifically say so. 6 | 7 | Here's a simple example in Rust: 8 | 9 | ```rust 10 | fn main() { 11 | let age = 25; // Here, we're creating a variable called 'age' and storing the value 25 in it. 12 | println!("Your age is: {}", age); // We can use the variable by referring to its name. 13 | } 14 | ``` 15 | 16 | In this example: 17 | - `let` is used to declare a variable in Rust. 18 | - `age` is the name of the variable. 19 | - `25` is the value we stored in the variable `age`. 20 | 21 | Now, if you want to change the value in the "box" (make it mutable), you would need to use `mut` to make the variable **mutable**: 22 | 23 | ```rust 24 | fn main() { 25 | let mut age = 25; // The 'mut' keyword allows the value to be changed later. 26 | println!("Your age is: {}", age); 27 | 28 | age = 26; // Now we can change the value. 29 | println!("Next year, you'll be: {}", age); 30 | } 31 | ``` 32 | 33 | In this case, we: 34 | - Declared `age` as mutable (`mut`). 35 | - Changed its value from `25` to `26` later in the program. 36 | 37 | So, in Rust: 38 | - Variables are **immutable** by default, which helps prevent accidental changes. 39 | - You need to use `mut` if you want to change the value of a variable. 40 | 41 | 42 | send a PR to ADD SOMETHING 43 | -------------------------------------------------------------------------------- /week-1/day-3.md: -------------------------------------------------------------------------------- 1 | In Rust, data types tell the program what kind of data it is dealing with, much like how you use containers in real life to store specific items (e.g., water goes in a bottle, books go on a shelf). 2 | 3 | for video examples see https://www.youtube.com/watch?v=o9mCVvEuKGg&list=PLDi2liHqCnVp0oM9rNp1Hy_H5aL6QUybN&index=5 4 | 5 | some basic data types in Rust: 6 | 7 | ### 1. **Integers** (Whole Numbers) 8 | - Think of integers as the type for counting or numbers without any fractions (like 1, 2, 100). 9 | - Example: `let age: i32 = 25;` 10 | Here, `i32` is a type for 32-bit integers. 11 | 12 | ### 2. **Floats** (Decimal Numbers) 13 | - Floats are numbers with decimal points, like 3.14 or 9.99. 14 | - Example: `let price: f64 = 10.99;` 15 | `f64` means it's a floating-point number with double precision (64-bit). 16 | 17 | ### 3. **Booleans** (True/False) 18 | - This is like a switch that can either be `true` (on) or `false` (off). 19 | - Example: `let is_student: bool = true;` 20 | 21 | ### 4. **Characters** (Single Letter/Emoji) 22 | - A `char` in Rust is for a single character, like a letter or even an emoji. 23 | - Example: `let grade: char = 'A';` or `let smiley: char = '😊';` 24 | 25 | ### 5. **Strings** (Text) 26 | - A `String` is like a list of characters strung together to form words or sentences. 27 | - Example: `let name: String = String::from("Mart");` 28 | 29 | ### 6. **Tuples** (Mixed Data Group) 30 | - Tuples let you group different types of values together, like a mini package that can hold multiple items. 31 | - Example: `let person: (String, i32) = (String::from("Mart"), 50);` 32 | This holds both a name and an age. 33 | 34 | ### 7. **Arrays** (Fixed-size List) 35 | - Arrays are a collection of items of the same type, like a row of identical storage boxes. 36 | - Example: `let numbers: [i32; 3] = [1, 2, 3];` 37 | This is an array of three integers. 38 | 39 | ### 8. **Vectors** (Growable List) 40 | - Vectors are like arrays, but they can grow and shrink in size. 41 | - Example: `let mut scores: Vec = vec![85, 90, 78];` 42 | 43 | These data types are used in Rust to ensure that the program knows how to handle different kinds of information efficiently. fine more information https://doc.rust-lang.org/book/ch03-02-data-types.html 44 | -------------------------------------------------------------------------------- /week-1/day-4.md: -------------------------------------------------------------------------------- 1 | # Fuction 2 | 3 | In Rust, a **function** is a small block of code that you can run whenever you need it to perform a specific task. Functions help you organize code so you can reuse tasks instead of rewriting the same code each time. 4 | 5 | for video example visit https://www.youtube.com/watch?v=YnwiRiXu5gA&list=PLDi2liHqCnVp0oM9rNp1Hy_H5aL6QUybN&index=15 6 | 7 | Here’s a basic way to understand it: 8 | 9 | Imagine you want to make a cup of tea. The steps are the same each time: 10 | 11 | 1. Boil water 12 | 2. Add tea bag 13 | 3. Pour water into a cup 14 | 4. Let it steep 15 | 16 | In Rust, you could create a function called `make_tea` that holds all these steps. Then, instead of explaining every single step each time, you can just say, "Run the `make_tea` function." 17 | 18 | #### NOTE 19 | The main fuction is the fuction that all functions are call inside it is where rust start execution from it specail type of fuction in rust 20 | 21 | Here's what this looks like in Rust code: 22 | 23 | ```rust 24 | fn make_tea() { 25 | println!("Boil water"); 26 | println!("Add tea bag"); 27 | println!("Pour water into a cup"); 28 | println!("Let it steep"); 29 | } 30 | ``` 31 | 32 | With this function in place, anytime you need to make tea, you just call `make_tea()` instead of rewriting each step. 33 | -------------------------------------------------------------------------------- /week-1/day-5.md: -------------------------------------------------------------------------------- 1 | ### Conditionals (Making Decisions) 2 | Conditionals let the program choose what to do based on some condition (whether something is true or false). 3 | 4 | vidoe for conditionals can be fine here https://www.youtube.com/watch?v=mLizOfB1bZE&list=PLDi2liHqCnVp0oM9rNp1Hy_H5aL6QUybN&index=6 5 | 6 | vidoe for loop can be fine here https://www.youtube.com/watch?v=t76yT6sNtzQ&list=PLDi2liHqCnVp0oM9rNp1Hy_H5aL6QUybN&index=8 7 | 8 | **Example:** Let's say you want to check if someone is old enough to vote. 9 | 10 | ``` 11 | fn main() { 12 | let age = 18; 13 | 14 | if age >= 18 { 15 | println!("You can vote!"); 16 | } else { 17 | println!("You are too young to vote."); 18 | } 19 | } 20 | ``` 21 | 22 | Here’s what’s happening: 23 | - `if age >= 18`: If the `age` is 18 or more, the program prints "You can vote!". 24 | - `else`: If the condition isn't true (meaning `age` is less than 18), it prints "You are too young to vote." 25 | 26 | Rust also allows `else if` for multiple conditions: 27 | 28 | ``` 29 | fn main() { 30 | let temperature = 25; 31 | 32 | if temperature > 30 { 33 | println!("It's hot outside!"); 34 | } else if temperature < 10 { 35 | println!("It's cold outside!"); 36 | } else { 37 | println!("The weather is nice."); 38 | } 39 | } 40 | ``` 41 | 42 | ### Loops (Repeating Actions) 43 | Loops allow you to repeat an action multiple times. 44 | 45 | 1. **`loop`**: This runs forever until you tell it to stop. 46 | 47 | ``` 48 | fn main() { 49 | let mut count = 0; 50 | 51 | loop { 52 | count += 1; 53 | println!("Count is: {}", count); 54 | 55 | if count == 5 { 56 | break; // stop the loop when count is 5 57 | } 58 | } 59 | } 60 | ``` 61 | 62 | 2. **`while`**: This runs as long as a condition is true. 63 | 64 | ``` 65 | fn main() { 66 | let mut count = 0; 67 | 68 | while count < 5 { 69 | count += 1; 70 | println!("Count is: {}", count); 71 | } 72 | } 73 | ``` 74 | 75 | In this example, the loop stops when `count` reaches 5. 76 | 77 | 3. **`for`**: This loop is used to go through a range of values or a collection like a list. 78 | 79 | ``` 80 | fn main() { 81 | for number in 1..5 { 82 | println!("Number: {}", number); 83 | } 84 | } 85 | ``` 86 | 87 | Here, `for` goes through each number from 1 to 4 (`1..5` means 1 up to, but not including, 5). 88 | 89 | ### Summary 90 | - **Conditionals** (`if`, `else`, `else if`): Help the program make decisions based on conditions. 91 | - **Loops** (`loop`, `while`, `for`): Help repeat actions multiple times based on certain conditions or ranges. 92 | -------------------------------------------------------------------------------- /week-1/day-6.md: -------------------------------------------------------------------------------- 1 | ### Program Overview: 2 | 3 | This Rust program is a simple command-line calculator that takes two numbers and an arithmetic operation (like addition, subtraction, division, or multiplication) from the user. It performs the specified operation and displays the result. 4 | 5 | ### How It's Built: 6 | 7 | 1. **Importing Libraries**: 8 | - The program starts by importing the `std::io` library, which is used to handle input and output. This allows the program to read data from the user through the terminal. 9 | 10 | 2. **Main Function**: 11 | - All the logic for the program is written inside the `main` function. This is the entry point of the program where everything starts. 12 | 13 | 3. **User Input**: 14 | - The program asks the user for two numbers: 15 | - It uses `println!` to display a message asking the user to enter the first number (`input1`). 16 | - It reads the user’s input using `std::io::stdin().read_line()` and stores it as a `String` in the `input1` variable. 17 | - The same process is repeated for the second number (`input2`). 18 | 19 | 4. **Asking for Operation**: 20 | - Next, the program asks what arithmetic operation the user wants to perform (e.g., `+`, `-`, `/`, `*`). 21 | - It reads the input into a variable called `opps`. 22 | 23 | 5. **Trimming and Parsing Input**: 24 | - The `trim()` function is used to remove any extra spaces around the user's input for both numbers and the operation. 25 | - The numbers entered by the user (as strings) are converted into `f32` (floating-point numbers) using `parse()`. If the conversion fails, the program will throw an error message asking the user to input valid numbers. 26 | 27 | 6. **Performing the Operation**: 28 | - The program checks which operation the user requested using a series of `if-else` statements: 29 | - **Addition (`+`)**: If the user entered a `+`, the program adds the two numbers and prints the result. 30 | - **Subtraction (`-`)**: If the user entered a `-`, it subtracts the second number from the first and prints the result. 31 | - **Division (`/`)**: If the user entered `/`, the program checks if the second number is zero to avoid dividing by zero (which would cause an error). If the second number is valid, it divides the first number by the second and prints the result. 32 | - **Multiplication (`*`)**: If the user entered `*`, it multiplies the two numbers and prints the result. 33 | - If the user enters an invalid operation (anything other than `+`, `-`, `/`, `*`), the program prints an error message asking the user to use one of the valid operations. 34 | 35 | 36 | -------------------------------------------------------------------------------- /week-1/day-7.md: -------------------------------------------------------------------------------- 1 | ### 1. **Ownership** 2 | Think of ownership like having the key to a car. If you have the key, you can drive it. In Rust, **ownership** means that only one person (or variable) has the key to use a piece of data at any time. 3 | 4 | - If you give someone else the key, you can't drive the car anymore. 5 | - When you're done with the car (your data goes out of scope), the car gets returned (the memory is freed). 6 | 7 | videos here https://www.youtube.com/watch?v=8M0QfLUDaaA 8 | more videos here https://www.youtube.com/watch?v=lQ7XF-6HYGc&t=1421s 9 | 10 | Example: 11 | ```rust 12 | let car1 = "Tesla"; // car1 owns the Tesla 13 | let car2 = car1; // car2 now owns the Tesla, car1 can't use it anymore 14 | // car1 is no longer valid here. 15 | ``` 16 | 17 | So, when you pass ownership, only one person can use the car at a time. 18 | 19 | ### 2. **Borrowing** 20 | Borrowing is like asking for the key to the car but without taking ownership of it. You’re just borrowing it for a while, and the owner still keeps the right to use the car after you're done. 21 | 22 | There are two kinds of borrowing: 23 | 24 | - **Immutable Borrowing** (no changes): You can borrow the car, but you can’t make any changes to it. 25 | - **Mutable Borrowing** (you can change it): You can borrow the car, but now you’re allowed to change the radio station or adjust the seats, for example. 26 | 27 | **The rules:** 28 | - You can have many people (references) borrow the car if no one is allowed to change anything. 29 | - Only one person can borrow it if they’re allowed to change something. 30 | 31 | Example: 32 | ```rust 33 | let car = "Tesla"; 34 | 35 | // Borrow without changing (immutable borrowing) 36 | let read_borrow = &car; // You can read it but not modify 37 | println!("{}", read_borrow); // Ok! 38 | 39 | // Borrow and change (mutable borrowing) 40 | let mut car2 = String::from("Tesla"); 41 | let modify_borrow = &mut car2; // You can change the car 42 | modify_borrow.push_str(" Model S"); // You added to the car name 43 | ``` 44 | 45 | So, borrowing lets you use someone else's car (data) without taking it away from them. 46 | 47 | ### 3. **Lifetimes** 48 | Lifetimes are like making sure the car (data) is still available while you’re using it. Rust ensures that you don’t hold onto a car key (a reference) after the car has been scrapped (data has been freed). 49 | 50 | Imagine you borrow a car, but then the car gets sold or destroyed while you still have the key—now you’re stuck with a key to a car that no longer exists! Rust’s **lifetimes** prevent that situation by making sure you can only use the car as long as it exists. 51 | 52 | Example: 53 | ```rust 54 | fn which_is_longer<'a>(car1: &'a str, car2: &'a str) -> &'a str { 55 | if car1.len() > car2.len() { 56 | car1 57 | } else { 58 | car2 59 | } 60 | } 61 | ``` 62 | 63 | Here, the `<'a>` makes sure both borrowed cars (data) are available as long as they’re being compared. It prevents you from trying to use a reference to something that’s already gone. 64 | 65 | ### Putting it Together 66 | - **Ownership**: Only one person can own the car (data) at a time. When they’re done, the car is returned (memory freed). 67 | - **Borrowing**: You can let others use the car (data) temporarily without giving them ownership. If they can change it, only one person can borrow it at a time. 68 | - **Lifetimes**: Rust ensures that borrowed data is still around while you’re using it, so you never try to drive a car that doesn’t exist anymore. 69 | 70 | 71 | -------------------------------------------------------------------------------- /week-1/day2code.rs: -------------------------------------------------------------------------------- 1 | // variables 2 | 3 | 4 | fn main() { 5 | 6 | // imutable variables 7 | let name = "John Doe"; 8 | let age = 30; 9 | let is_student = true; 10 | let height = 1.75; 11 | 12 | // formatted string with placeholders 13 | println!("Hello, my name is {}. I'm {} years old. I'm a student: {}. My height is {} meters.", name, age, is_student, height); 14 | 15 | 16 | // mutable variables 17 | let mut weight = 75.0; 18 | let mut nationality = "American"; 19 | weight += 10.0; 20 | nationality = "British"; 21 | println!("My current weight is {} kg. I'm from {}.", weight, nationality); 22 | 23 | // variable shadowing 24 | let name = "Jane Doe"; 25 | println!("My new name is {}", name); 26 | 27 | // variable scope 28 | { 29 | let name = "Alice"; 30 | println!("Inside the scope: My name is {}", name); 31 | } 32 | 33 | 34 | } 35 | 36 | 37 | -------------------------------------------------------------------------------- /week-1/day3code.rs: -------------------------------------------------------------------------------- 1 | // datatype 2 | 3 | fn main() { 4 | 5 | let age: u8 = 30; // Integer (u8: unsigned 8-bit integer) 6 | 7 | let birth_year: i32 = 1993; // Integer (i32: signed 32-bit integer) 8 | 9 | let population: i64 = 7_800_000_000; // Integer (i64: signed 64-bit integer) 10 | 11 | let height: f32 = 1.8; // Floating point number (f32: 32-bit float) 12 | 13 | let weight: f64 = 75.5; // Floating point number (f64: 64-bit float) 14 | 15 | let name: &str = "John Doe"; // String slice (&str: borrowed string, fixed length) 16 | 17 | let full_name: String = String::from("Jonathan Doe"); // String (String: growable heap-allocated string) 18 | 19 | let is_student: bool = true; // Boolean (true or false) 20 | 21 | let grade: char = 'A'; // Character (char: single character, 4 bytes) 22 | 23 | let fav_numbers: [u8; 5] = [1, 2, 3, 4, 5]; // Array of unsigned 8-bit integers (fixed-size array) 24 | 25 | let person_info: (i32, f64, &str) = (30, 75.5, "John Doe"); // Tuple (fixed-size, can contain multiple types) 26 | 27 | let addresses: Vec = vec![String::from("123 Main St"), String::from("456 Elm St")]; // Vector of Strings (dynamic, growable array of Strings) 28 | 29 | // Print the values 30 | println!("Age (u8): {}", age); 31 | println!("Birth year (i32): {}", birth_year); 32 | println!("World population (i64): {}", population); 33 | println!("Height (f32): {}", height); 34 | println!("Weight (f64): {}", weight); 35 | println!("Name (&str): {}", name); 36 | println!("Full name (String): {}", full_name); 37 | println!("Is student (bool): {}", is_student); 38 | println!("Grade (char): {}", grade); 39 | println!("Favorite numbers (array): {:?}", fav_numbers); // {:?} is used to print arrays 40 | println!("Person info (tuple): {:?}", person_info); // {:?} is used to print tuples 41 | println!("Addresses (Vec): {:?}", addresses); // {:?} is used to print vectors 42 | 43 | } 44 | -------------------------------------------------------------------------------- /week-1/day4code.rs: -------------------------------------------------------------------------------- 1 | // fuction 2 | 3 | fn main() { 4 | println!("Hello, world!"); 5 | greet("John Doe"); 6 | println!("The sum of 5 and 3 is {}", add(5, 3)); 7 | let (result, is_divisible) = divide(10.0, 2.0); 8 | println!("The result is {} and it is {} divisible by 2.", result, if is_divisible { "is" } else { "is not" }); 9 | 10 | } 11 | 12 | // function with parameters 13 | 14 | fn greet(name: &str) { 15 | println!("Hello, {}!", name); 16 | } 17 | 18 | // function with return value 19 | 20 | fn add(x: i32, y: i32) -> i32 { 21 | x + y 22 | } 23 | 24 | // function with multiple return values 25 | 26 | fn divide(x: f64, y: f64) -> (f64, bool) { 27 | if y == 0.0 { 28 | (0.0, false) 29 | } else { 30 | (x / y, true) 31 | } 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /week-1/day5code.rs: -------------------------------------------------------------------------------- 1 | // conditional and loop 2 | 3 | fn main() { 4 | let mut number = 4; 5 | let ahlpa = 20; 6 | 7 | if ahlpa % 2 == 0 { 8 | println!("The number {} is even.", ahlpa); 9 | } else if ahlpa % 2 == 1 { 10 | println!("The number {} is odd.", ahlpa); 11 | }else{ 12 | println!("The number {} is neither even nor odd.", ahlpa); 13 | } 14 | 15 | for i in 0..10 { 16 | println!("Loop iteration: {}", i); 17 | } 18 | 19 | while number % 2 == 0 { 20 | println!("The number {} is still even.", number); 21 | number += 1; 22 | if number > 10 { 23 | break; 24 | } 25 | continue; 26 | } 27 | 28 | loop { 29 | println!("Infinite loop iteration: {}", number); 30 | number += 1; 31 | if number > 10 { 32 | break; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /week-1/day6project.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | 3 | 4 | fn main(){ 5 | 6 | // read input from command line 7 | println!("Enter a number 1:"); 8 | let mut input1 = String::new(); 9 | std::io::stdin().read_line(&mut input1).expect("Failed to read line"); 10 | 11 | println!("Enter a number 2:"); 12 | let mut input2 = String::new(); 13 | io::stdin().read_line(&mut input2).expect("Failed to read line"); 14 | 15 | println!("what operation do you want to do (+,-,/,*)"); 16 | let mut opps= String::new(); 17 | std::io::stdin().read_line(&mut opps).expect("Failed to read line"); 18 | 19 | // eliminate whites spaces from the input 20 | let num1: f32 = input1.trim().parse().expect("Please input a number"); 21 | let num2: f32 = input2.trim().parse().expect("Please input a number"); 22 | let opp = opps.trim(); 23 | 24 | // perform the operation 25 | if opp == "+" { 26 | let result = num1 + num2; // addition 27 | println!("The sum is: {}", result); 28 | } else if opp == "-" { 29 | let result = num1 - num2; // substraction 30 | println!("The difference is: {}", result); 31 | } else if opp == "/" { 32 | if num2 == 0.0 { 33 | println!("Error: Division by zero is not allowed"); 34 | } else { 35 | let result = num1 / num2; // division 36 | println!("The division is: {}", result); 37 | } 38 | 39 | } else if opp == "*" { 40 | let result = num1 * num2; // multiplication 41 | println!("The product is: {}", result ); 42 | 43 | } else { 44 | println!("Invalid operation. Please use +,-,/,*"); 45 | } 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /week-1/day7code.rs: -------------------------------------------------------------------------------- 1 | // ownership , borrowing and lifetimes 2 | 3 | // lifetime of a variable is the duration for which the variable is valid and can be accessed. 4 | 5 | fn which_is_longer<'a>(car1: &'a str, car2: &'a str) -> &'a str { 6 | if car1.len() > car2.len() { 7 | car1 8 | } else { 9 | car2 10 | } 11 | } 12 | 13 | 14 | fn main() { 15 | // ownership 16 | let car1 = "Tesla"; // car1 owns the Tesla 17 | let car2 = car1; // car2 now owns the Tesla, car1 can't use it anymore 18 | println!("{}", car2); // prints Tesla 19 | 20 | // uncomment the following to see the error showing car1 no longer valid 21 | // println!("{}", car1); // prints Tesla 22 | // car1 is no longer valid here. 23 | 24 | 25 | 26 | // borrowing 27 | 28 | let car = "Tesla"; 29 | // Borrow without changing (immutable borrowing) 30 | let read_borrow = &car; // You can read it but not modify 31 | println!("{}", read_borrow); // Ok! 32 | 33 | // Borrow and change (mutable borrowing) 34 | let mut car2 = String::from("Tesla"); 35 | let modify_borrow = &mut car2; // You can change the car 36 | modify_borrow.push_str(" Model S"); 37 | println!("modify borrow is {}", modify_borrow); 38 | 39 | // lifetime 40 | let car1 = "Tesla"; 41 | let car2 = "Toyota"; 42 | let longest = which_is_longer(car1, car2); 43 | println!("The longest car is {}", longest); 44 | println!("{}", car1); // prints Tesla, car1 is still valid here. 45 | println!("{}", car2); // prints Toyota, car2 is still valid here. 46 | 47 | 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /week-2/README.md: -------------------------------------------------------------------------------- 1 | ## Week 2: Structs, Enums, and Error Handling 2 | 3 | **Day 8-9:** 4 | - Learn about structs and enums. 5 | - **Project:** Build a small inventory management system using structs and enums. 6 | 7 | **Day 10-11:** 8 | - Understand pattern matching and control flow. 9 | - **Project:** Add pattern matching to the inventory system, allowing for item categorization. 10 | 11 | **Day 12-14:** 12 | - Deep dive into Rust's error handling with `Result` and `Option`. 13 | - **Project:** Add error handling to the inventory, making it more robust. -------------------------------------------------------------------------------- /week-2/day-8.md: -------------------------------------------------------------------------------- 1 | # Structs 2 | 3 | In Rust, a **struct** is like a blueprint for creating custom types. Think of it like a form you fill out. Each struct can hold multiple pieces of related data, called **fields**, each with its own type. 4 | 5 | for vidoe explanation of the struct visit here: https://www.youtube.com/watch?v=aSzyVVz57L8&list=PLDi2liHqCnVp0oM9rNp1Hy_H5aL6QUybN&index=21 6 | 7 | Here's a simple way to understand it: 8 | 9 | Imagine you're creating a blue print to describe a book: 10 | 11 | - **Title**: "Rust Programming" 12 | - **Author**: "Mart RUST " 13 | - **Pages**: 350 14 | 15 | In Rust, you can create a **struct** called `Book` to hold this information. The **struct** would have fields for `title`, `author`, and `pages`, each with a specific data type. Then, when you want to describe a book, you'd fill in these fields, just like completing a form. 16 | 17 | Here's an example in Rust: 18 | 19 | ```rust 20 | struct Book { 21 | title: String, 22 | author: String, 23 | pages: u32, // u32 means a 32-bit unsigned integer for page numbers 24 | } 25 | 26 | fn main() { 27 | let my_book = Book { 28 | title: String::from("Rust Programming"), 29 | author: String::from("John Doe"), 30 | pages: 350, 31 | }; 32 | 33 | println!("The book '{}' by {} has {} pages.", my_book.title, my_book.author, my_book.pages); 34 | } 35 | ``` 36 | 37 | ### Key Points: 38 | - **Structs** group related information. 39 | - Each field in the struct has a name (like "title" or "author") and a type (like `String` or `u32`). 40 | - Once you define a struct, you can create instances of it (like `my_book` in the example) and fill in the data. 41 | -------------------------------------------------------------------------------- /week-2/day8code.rs: -------------------------------------------------------------------------------- 1 | // struct 2 | 3 | // Person struct definition with fields and methods 4 | // `#[derive(Debug)]` attribute for printing the struct in a human-readable format 5 | struct Person { 6 | name: String, 7 | age: u8, 8 | nationality: String, 9 | } 10 | 11 | fn main() { 12 | let person1 = Person { 13 | name: String::from("John"), 14 | age: 30, 15 | nationality: String::from("American"), 16 | }; 17 | //println!("{:?}", person1); 18 | println!("Name: {}, Age: {}, Nationality: {}", person1.name, person1.age, person1.nationality); 19 | 20 | let person2 = Person { 21 | name: String::from("Jane"), 22 | age: 25, 23 | nationality: String::from("British"), 24 | }; 25 | //println!("{:?}", person2); 26 | println!("Name: {}, Age: {}, Nationality: {}", person2.name, person2.age, person2.nationality); 27 | 28 | let mut person3 = Person { 29 | name: String::from("Alice"), 30 | age: 28, 31 | nationality: String::from("American"), 32 | }; 33 | 34 | person3.age += 1; 35 | //println!("{:?}", person3); 36 | println!("Name: {}, Age: {}, Nationality: {}", person3.name, person3.age, person3.nationality); 37 | } 38 | -------------------------------------------------------------------------------- /week-3/README.md: -------------------------------------------------------------------------------- 1 | ## Week 3: Collections and Iterators 2 | 3 | **Day 15-17:** 4 | - Learn about vectors, hash maps, and strings. 5 | - **Project:** Build a contact book app, allowing for the addition, removal, and search of contacts. 6 | 7 | **Day 18-19:** 8 | - Master iterators and closures. 9 | - **Project:** Add sorting and filtering options to the contact book using iterators. 10 | 11 | **Day 20-21:** 12 | - Study traits and generics in Rust. 13 | - **Project:** Refactor the contact book to make it more generic and reusable. -------------------------------------------------------------------------------- /week-4/README.md: -------------------------------------------------------------------------------- 1 | ## Week 4: Async Programming and Concurrency 2 | 3 | **Day 22-25:** 4 | - Learn async programming with `tokio`. 5 | - **Project:** Build an asynchronous web scraper that fetches and processes data from multiple websites concurrently. 6 | 7 | **Day 26-28:** 8 | - Study concurrency using threads. 9 | - **Project:** Modify the web scraper to handle multiple scraping tasks concurrently. -------------------------------------------------------------------------------- /week-5/README.md: -------------------------------------------------------------------------------- 1 | ## Week 5: Working with Files, Crates, and Modules 2 | 3 | **Day 29-31:** 4 | - Learn file I/O in Rust and how to use crates. 5 | - **Project:** Build a log parser that reads logs from a file and generates a report. 6 | 7 | **Day 32-34:** 8 | - Learn about Rust modules and crate structures. 9 | - **Project:** Refactor the log parser to be modular and scalable. -------------------------------------------------------------------------------- /week-6/README.md: -------------------------------------------------------------------------------- 1 | 2 | **Day 35-38:** 3 | - Study basic web development in Rust using `actix-web` , `warp`, `rocket` and `axum`. 4 | - **Project:** Create a simple REST API for a TODO app. 5 | 6 | **Day 39-41:** 7 | - Add database integration with `SQLx` or `Diesel`. 8 | - **Project:** Extend the TODO app to store tasks in a Postgres or SQLite database. 9 | -------------------------------------------------------------------------------- /week-7/README.md: -------------------------------------------------------------------------------- 1 | ## Week 7: Advanced Topics (FFI, Unsafe, Macros) 2 | 3 | **Day 42-44:** 4 | - Learn about Foreign Function Interface (FFI) and using C libraries in Rust. 5 | - **Project:** Build a small Rust application that uses a C library for some functionality. 6 | 7 | **Day 45-47:** 8 | - Dive into unsafe Rust. 9 | - **Project:** Build a memory-efficient data structure using unsafe code for performance optimization. 10 | 11 | **Day 48-50:** 12 | - Study Rust macros and how to create your own. 13 | - **Project:** Create a custom derive macro to automatically generate code for common tasks in one of your previous projects. --------------------------------------------------------------------------------