Skip to content

πŸ¦€ 30 Days of Rust is a daily challenge to guide you through Rust programming essentials. From basics to advanced, this repo offers πŸ“š clear examples, πŸ”§ practical exercises, and 🎯 resources to help you master Rust, one day at a time. Whether you're new or refining your skills, this challenge has something for you. Join the journey now! πŸš€

License

Notifications You must be signed in to change notification settings

Hunterdii/30-Days-Of-Rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

80 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ¦€ 30 Days of Rust

Day Topics
01 Introduction to Rust
02 Variables, Data Types
03 Control Flow
04 Functions
05 Ownership and Borrowing
06 Structs
07 Enums
08 Collections
09 Error Handling
10 Generics
11 Traits
12 Modules and Crates
13 Testing
14 Cargo and Package Management
15 Macros
16 File Handling
17 Concurrency
18 Asynchronous Programming

πŸš€ Happy Coding in Rust! πŸ¦€

Star Badge Pull Requests MIT License Open Source Badge GitHub Contributors Last Commit Owner Badge

Github Stats:

🌟 Stars 🍴 Forks πŸ› Issues πŸ“ Repo Size πŸ”” Open PRs πŸ”• Closed PRs
Stars Forks Issues Repo Size Open Pull Requests Closed Pull Requests
Support the author to create more educational materials
Paypal Logo

πŸ¦€ 30 Days Of Rust: Day 1 - Introduction πŸš€

LinkedIn Follow me on GitHub

Author: Het Patel

October, 2024

Day 2 >>

30DaysOfRust

πŸ“˜ Day 1 - Introduction to Rust

πŸ‘‹ Welcome

Welcome to Day 1 of your exciting journey through Rust programming! πŸš€ Today, we’ll dive into setting up Rust, exploring its unique features, and writing your very first Rust program. Get ready to embark on a fun and engaging adventure! 🎯

Congratulations! πŸŽ‰ You've taken the first step in your journey to master the 30 Days of Rust programming challenge. In this challenge, you will learn the fundamentals of Rust and how to harness its power to write efficient, fast, and safe code. By the end of this journey, you'll have gained a solid understanding of Rust's core concepts and best practices, helping you become a confident Rustacean. πŸ¦€

Feel free to join the 30 Days of Rust community on Discord, where you can interact with others, ask questions, and share your progress!

πŸ” Introduction

Rust is a systems programming language focused on safety, speed, and concurrency. It’s known for its memory safety features and its ability to build fast and efficient software. Whether you're building web applications, embedded software, or system-level programs, Rust is your go-to language. 🦾

Rust is a modern, systems programming language that aims to combine safety, speed, and concurrency. Developed by Mozilla, it’s designed to be a safe alternative to languages like C and C++, without compromising on performance. Rust has quickly gained popularity due to its unique ownership model, which helps prevent common bugs like null pointer dereferencing and data races at compile time.

Throughout this challenge, you’ll learn the latest version of Rust, step-by-step, with easy-to-understand explanations, real-world examples, and hands-on exercises. Whether you’re a beginner or a professional looking to enhance your skills, this challenge will guide you in understanding the core aspects of Rust in a fun, engaging, and motivating way.

πŸ’‘ Why Rust?

Rust is a powerful, yet beginner-friendly language that can be used for various applications such as:

  • Concurrency: Makes it easier to write concurrent programs.
  • Community: A growing and welcoming community ready to help you learn.
  • Data science and machine learning: Rust's speed and safety are attracting developers who are building data-intensive applications.
  • Game development: Thanks to its high performance, Rust is also suitable for game development.
  • System programming: Rust’s low-level control over system resources makes it ideal for building operating systems, embedded software, and more.
  • Safety: Prevents common bugs like null pointer dereferencing and data races.
  • Speed: Compiles to native code, ensuring faster execution.
  • Web development: Rust can be used to build both back-end and front-end (with frameworks like Yew).

πŸ”‘ If you’re looking for a language that blends performance with reliability, Rust is the way to go!

These are just a few of the many use cases that make Rust a versatile and in-demand language. 🌟 Ready to start coding in Rust?

πŸ›  Environment Setup

πŸ“₯ Installing Rust

To run Rust code, you need to have Rust installed on your system. Let’s get started by downloading Rust. Follow the installation guide to set up Rust:

For Windows users, run this command in the terminal:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

For macOS and Linux users, use the same command in your terminal.

Once you have Rust installed, you can verify it by checking the version:

rustc --version

If the command outputs a version number, you’re good to go! πŸŽ‰

πŸ’» Installing Visual Studio Code

While Rust can be coded in any text editor, we'll use Visual Studio Code for this challenge. It’s a powerful, customizable, and widely used code editor. If you haven’t already, download Visual Studio Code and set it up.

Make sure to install the Rust extension on Visual Studio Code for syntax highlighting, code formatting, and error checking:

  1. Open Visual Studio Code.
  2. Go to Extensions (or press Ctrl+Shift+X).
  3. Search for rust-analyzer and install it.

Now, you're ready to start coding! ✨

πŸ›  Setting Up Your First Rust Project

Let’s create our first Rust project using Cargo, Rust's package manager. Open your terminal and run:

cargo new hello-rust

This command will create a new directory named hello-rust with the necessary files. Change to the project directory:

cd hello-rust

Inside, you'll find Cargo.toml (a manifest file for Rust projects) and a src directory containing main.rs. Let's explore what’s inside.

fn main() {
    println!("Hello, Rust!");
}

To run your first Rust program, type:

cargo run

You should see the output:

Hello, Rust!

Congratulations! πŸŽ‰ You’ve successfully set up your Rust development environment and run your first Rust program.

πŸ›‘οΈ Boom! You’ve successfully written and executed your first Rust program!


🎯 Hands-On Challenge

Create a Rust program that prints your name and the reason you're excited to learn Rust. Here’s a template to get you started:

fn main() {
    let name = "Your Name";
    let reason = "I'm excited to learn Rust because it's fast and reliable!";
    println!("Hello, my name is {} and {}.", name, reason);
}

βœ… Share your solution on GitHub and tag #30DaysOfRust on social media! Let the world know you’ve begun your Rust journey! πŸš€


πŸŽ₯ Helpful Video References

Get a better understanding of Rust and how it works by checking out these great resources:

  1. Rust for Beginners - Complete Guide
    A comprehensive guide that walks you through the basics of Rust.

  2. Why Rust? - A Love Letter to Rust
    Learn why Rust has become so popular in recent years.

  3. Build Your First Rust Project
    Create a complete project from scratch with this hands-on video.

πŸ“– Understanding Rust Basics

πŸ”€ Rust Syntax

Rust syntax is clear and concise, making it easy to write and understand. Let’s explore some of the essential elements you’ll need to get started.

πŸ’¬ Comments

In Rust, comments are crucial for explaining your code and making it more understandable. They can be categorized into non-doc comments and doc comments.

  • Non-doc Comments
    • Single-Line Comments
    • MultiLine Comments
  • Doc Comments
    • Outer doc comments
    • Inner doc comments

Non-Doc Comments

Non-doc comments are used to annotate your code without being part of the documentation generated by tools like rustdoc. They are primarily for developers working directly with the code.

Single-Line Comments

Single-line comments start with // and continue to the end of the line. They are useful for short explanations.

Example:

fn main() {
    let x = 5; // This is a single-line comment
    println!("Value of x: {}", x);
}

Output:

Value of x: 5

Multi-Line Comments

Multi-line comments start with /* and end with */. They can span multiple lines, making them suitable for longer explanations.

Example:

fn main() {
    /* This is a multi-line comment.
       It can span multiple lines.
       The next line will print the value of x. */
    let x = 10;
    println!("Value of x: {}", x);
}

Output:

Value of x: 10

Doc Comments

Doc comments are used to document public APIs and generate documentation using tools like rustdoc. They start with /// for outer doc comments and //! for inner doc comments.

Outer Doc Comments

Outer doc comments are placed before functions, structs, or modules and are used to describe them in the generated documentation.

Example:

/// This function adds two numbers and returns the result.
fn add(a: i32, b: i32) -> i32 {
    a + b
}

In this example, /// provides a description of what the add function does. This comment will appear in the documentation generated by rustdoc.

Inner Doc Comments

Inner doc comments are placed within the context of a module, function, or struct, usually to provide more details about the implementation.

Example:

/// A structure representing a point in 2D space.
struct Point {
    x: f64,
    y: f64,
}

impl Point {
    /// Creates a new Point at the given coordinates.
    ///
    /// # Examples
    ///
    /// ```
    /// let p = Point::new(1.0, 2.0);
    /// ```
    fn new(x: f64, y: f64) -> Self {
        Point { x, y }
    }
}

In this example, /// describes the Point struct and the new method. The /// before the new method serves as a doc comment that explains what the method does and provides an example.

πŸ’» Exercises - Day 1

βœ… Exercise: Level 1

  1. Create a new Rust project using Cargo.
  2. Write a program that prints Hello, World! to the console.
  3. Verify that Rust is installed correctly by checking its version.

βœ… Exercise: Level 2

  1. Modify the main.rs file to declare an immutable variable x with the value of 5.
  2. Change x to be mutable and update its value to 10.

βœ… Exercise: Level 3 (OPTIONAL)

  1. Write a Rust program that declares different data types (integer, float, boolean, string) and prints them.
  2. Experiment with different control flow structures (if, else, for, while).

πŸ“ Day 1 Summary

  • We covered the installation of Rust.
  • You wrote your first Rust program.
  • You explored helpful video resources to dive deeper into Rust.
  • You completed your first hands-on challenge.

πŸ‘ Well done on making it through Day 1! Pat yourself on the back and get ready for the next step!

πŸŒ• Great job! You have completed Day 1 of the 30 Days of Rust challenge! Keep practicing, and get ready for Day 2 where you'll dive deeper into Rust basics.

Thank you for joining Day 1 of the 30 Days of Rust challenge! If you found this helpful, don’t forget to Star GIF star this repository, share it with your friends, and stay tuned for more exciting lessons ahead!

Stay Connected
πŸ“§ Email: Hunterdii
🐦 Twitter: @HetPate94938685
🌐 Website: Working On It(Temporary)

Day 2 >>


About

πŸ¦€ 30 Days of Rust is a daily challenge to guide you through Rust programming essentials. From basics to advanced, this repo offers πŸ“š clear examples, πŸ”§ practical exercises, and 🎯 resources to help you master Rust, one day at a time. Whether you're new or refining your skills, this challenge has something for you. Join the journey now! πŸš€

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published