Skip to content

onurturhan/rusty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

13 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿฆ€ Rust Learning Project

๐ŸŽ‰ Welcome to Rust! Your learning environment is ready!

This comprehensive Rust learning setup will take you from beginner to intermediate level with hands-on examples and structured exercises.

๐Ÿฆ€ What is Rust?

Rust is a systems programming language focused on:

  • Memory Safety: No null pointer dereferences, buffer overflows, or memory leaks
  • Performance: Zero-cost abstractions, no garbage collector
  • Concurrency: Safe concurrent programming
  • Cross-platform: Runs on many platforms and architectures

๐Ÿ“ Project Structure

rust_learning/
โ”œโ”€โ”€ README.md                    # This file - complete learning guide
โ”œโ”€โ”€ rust_cheatsheet.md          # Quick syntax reference
โ”œโ”€โ”€ exercises.md                # 7 structured practice exercises
โ”‚
โ”œโ”€โ”€ examples/                   # Working code examples (numbered in learning order)
โ”‚   โ”œโ”€โ”€ 001-variables_and_data_types.rs # Variables, mutability, and all data types
โ”‚   โ”œโ”€โ”€ 002-functions.rs        # Function examples
โ”‚   โ”œโ”€โ”€ 003-control_flow.rs     # If/else, loops, and match
โ”‚   โ”œโ”€โ”€ 004-ownership_borrowing.rs # Ownership and borrowing
โ”‚   โ”œโ”€โ”€ 005-structs_enums.rs    # Structs and enums with methods
โ”‚   โ”œโ”€โ”€ 006-pattern_matching.rs # Advanced pattern matching
โ”‚   โ”œโ”€โ”€ 007-error_handling.rs   # Result and Option types
โ”‚   โ”œโ”€โ”€ 008-collections.rs      # Vec, HashMap, HashSet, and other collections
โ”‚   โ”œโ”€โ”€ 009-generics-traits.rs  # Generic types and trait system
โ”‚   โ”œโ”€โ”€ 010-lifetimes.rs        # Lifetime annotations and management
โ”‚   โ”œโ”€โ”€ 011-modules-crates.rs   # Module system and crate organization
โ”‚   โ”œโ”€โ”€ 012-file-io.rs          # File I/O operations and path handling
โ”‚   โ”œโ”€โ”€ 013-testing.rs          # Unit testing and test organization
โ”‚   โ”œโ”€โ”€ 014-command-line.rs     # Building command-line programs
โ”‚   โ”œโ”€โ”€ 015-concurrency-threads.rs # Concurrency and Threads (channels, Mutex, Arc)
โ”‚   โ”œโ”€โ”€ 016-async-programming.rs # Asynchronous Programming (async/await, Tokio)
โ”‚   โ”œโ”€โ”€ 017-unsafe-rust.rs      # Unsafe Rust (raw pointers, FFI)
โ”‚   โ”œโ”€โ”€ 018-macros.rs           # Macros (declarative, procedural)
โ”‚   โ”œโ”€โ”€ 019-web-development.rs  # Web Development (frameworks, HTTP, APIs)
โ”‚   โ””โ”€โ”€ 020-system-programming.rs # System Programming (OS interaction, low-level networking)
โ”‚
โ”œโ”€โ”€ exercises/                  # Practice exercises directory
โ”‚   โ””โ”€โ”€ ex1_variables.rs        # Exercise 1 (example)
โ”‚
โ”œโ”€โ”€ hello_rust/                 # Your first Cargo project
โ”‚   โ”œโ”€โ”€ Cargo.toml              # Project configuration
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ””โ”€โ”€ main.rs             # "Hello, world!" program
โ”‚   โ””โ”€โ”€ target/                 # Compiled output (auto-generated)
โ”‚
โ””โ”€โ”€ guessing_game/              # Interactive number guessing game
    โ”œโ”€โ”€ Cargo.toml              # Project configuration with dependencies
    โ”œโ”€โ”€ src/
    โ”‚   โ””โ”€โ”€ main.rs             # Complete guessing game code
    โ””โ”€โ”€ target/                 # Compiled output (auto-generated)

๐Ÿ“ What's in your rust_learning directory:

  1. rust_cheatsheet.md - Quick reference for Rust syntax

  2. exercises.md - 7 structured exercises to practice

  3. examples/ - Working code examples (numbered in learning order):

    Phase 1 (Basics):

    • 001-variables_and_data_types.rs - Variables, mutability, and all data types
    • 002-functions.rs - Function examples
    • 003-control_flow.rs - If/else, loops, and match
    • 004-ownership_borrowing.rs - Ownership and borrowing
    • 005-structs_enums.rs - Structs and enums with methods
    • 006-pattern_matching.rs - Advanced pattern matching
    • 007-error_handling.rs - Result and Option types

    Phase 2 (Intermediate):

    • 008-collections.rs - Vec, HashMap, HashSet, and other collections
    • 009-generics-traits.rs - Generic types and trait system
    • 010-lifetimes.rs - Lifetime annotations and management
    • 011-modules-crates.rs - Module system and crate organization
    • 012-file-io.rs - File I/O operations and path handling
    • 013-testing.rs - Unit testing and test organization
    • 014-command-line.rs - Building command-line programs

    Phase 3 (Advanced):

    • 015-concurrency-threads.rs - Concurrency and Threads (channels, Mutex, Arc)
    • 016-async-programming.rs - Asynchronous Programming (async/await, Tokio)
    • 017-unsafe-rust.rs - Unsafe Rust (raw pointers, FFI)
    • 018-macros.rs - Macros (declarative, procedural)
    • 019-web-development.rs - Web Development (frameworks, HTTP, APIs)
    • 020-system-programming.rs - System Programming (OS interaction, low-level networking)
  4. exercises/ - Practice exercises directory with example solutions

  5. hello_rust/ - Your first Cargo project

  6. guessing_game/ - Interactive number guessing game (ready to play!)

๐Ÿš€ Your next steps:

  1. Try the guessing game right now:

    cd guessing_game && cargo run
  2. Run the examples (in order):

    # Phase 1 (Basics)
    rustc examples/001-variables_and_data_types.rs -o 001-variables_and_data_types && ./001-variables_and_data_types
    rustc examples/002-functions.rs -o 002-functions && ./002-functions
    rustc examples/003-control_flow.rs -o 003-control_flow && ./003-control_flow
    
    # Phase 2 (Intermediate) - Try after completing Phase 1
    rustc examples/008-collections.rs -o 008-collections && ./008-collections
    rustc examples/009-generics-traits.rs -o 009-generics-traits && ./009-generics-traits
  3. Start with Exercise 1 - Create your first program following the exercises.md

  4. Use the cheatsheet - Keep rust_cheatsheet.md open as reference

๐ŸŽฏ Key Rust concepts to focus on:

Phase 1 (Basics):

  • Ownership (most unique/important concept)
  • Borrowing and references (&)
  • Pattern matching with match
  • Error handling with Result and Option

Phase 2 (Intermediate):

  • Collections for data storage (Vec, HashMap)
  • Generics and Traits for code reusability
  • Lifetimes for advanced memory management
  • Modules for code organization
  • Testing for code reliability

๐Ÿ’ก Pro tips:

  • Read compiler error messages carefully - Rust's compiler is very helpful!
  • Use cargo check for faster error checking
  • Don't worry about lifetimes initially - focus on ownership first
  • Practice daily, even just 15 minutes

๐Ÿ“š Learning Path Overview

Phase 1: Basics (Days 1-7) โœ… Complete!

  1. Variables and Data Types โœ… (mutability, constants, shadowing, scalar/compound types)
  2. Functions โœ… (parameters, return values, expressions vs statements)
  3. Control Flow โœ… (if/else, loops, match expressions, nested patterns)
  4. Ownership and Borrowing โœ… (move semantics, references, lifetimes, string slices)
  5. Structs and Enums โœ… (methods, associated functions, complex enum variants)
  6. Pattern Matching โœ… (match guards, destructuring, if let/while let)
  7. Error Handling โœ… (Result/Option types, ? operator, custom errors)

Phase 2: Intermediate (Days 8-14) โœ… Complete!

  1. Collections โœ… (Vec, HashMap, HashSet, VecDeque, BTreeMap, iterator patterns)
  2. Generics and Traits โœ… (generic functions/structs, trait bounds, associated types)
  3. Lifetimes โœ… (lifetime annotations, elision rules, static lifetimes)
  4. Modules and Crates โœ… (module system, privacy, use statements, external crates)
  5. File I/O โœ… (reading/writing files, buffered I/O, path operations)
  6. Testing โœ… (unit tests, integration tests, assertions, test organization)
  7. Command Line Programs โœ… (args, environment variables, stdin/stdout, CLI tools)

Phase 3: Advanced (Days 15+) ๐Ÿšง Work in Progress

  1. Concurrency and Threads ๐Ÿšง (channels, Mutex, Arc)
  2. Async Programming ๐Ÿšง (async/await, Tokio, Futures)
  3. Unsafe Rust ๐Ÿšง (raw pointers, FFI, unsafe keyword)
  4. Macros ๐Ÿšง (declarative, procedural, custom macros)
  5. Web Development ๐Ÿšง (frameworks like Actix Web/Axum, HTTP, APIs)
  6. System Programming ๐Ÿšง (OS interaction, low-level networking, embedded)

๐Ÿ› ๏ธ Essential Cargo Commands

# Create a new project
cargo new project_name

# Build the project
cargo build

# Run the project
cargo run

# Check for errors without building
cargo check

# Run tests
cargo test

# Build optimized version
cargo build --release

๐ŸŽฎ Quick Start

Get started immediately with these commands:

# Play the guessing game
cd guessing_game && cargo run

# Try the examples (in order)
# Phase 1 examples
rustc examples/001-variables_and_data_types.rs -o 001-variables_and_data_types && ./001-variables_and_data_types
rustc examples/002-functions.rs -o 002-functions && ./002-functions
rustc examples/003-control_flow.rs -o 003-control_flow && ./003-control_flow

# Phase 2 examples (intermediate)
rustc examples/008-collections.rs -o 008-collections && ./008-collections
rustc examples/009-generics-traits.rs -o 009-generics-traits && ./009-generics-traits
rustc examples/010-lifetimes.rs -o 010-lifetimes && ./010-lifetimes

# Try the first exercise
rustc exercises/ex1_variables.rs -o ex1_variables && ./ex1_variables
# Then complete more exercises following exercises.md

๐Ÿ”ง Development Tips

Compiler is Your Friend

  • Read error messages carefully - they're very helpful!
  • Use cargo check for faster error checking
  • Don't fight the borrow checker - learn from it
  • Use cargo fmt to format your code
  • Use cargo clippy for additional lints

Common Rust Patterns

Error Handling

// Using Result
fn divide(a: f64, b: f64) -> Result<f64, String> {
    if b == 0.0 {
        Err("Division by zero".to_string())
    } else {
        Ok(a / b)
    }
}

// Using Option
fn find_word(text: &str, word: &str) -> Option<usize> {
    text.find(word)
}

Iterator Patterns

let numbers = vec![1, 2, 3, 4, 5];

// Filter and collect
let evens: Vec<i32> = numbers
    .iter()
    .filter(|&x| x % 2 == 0)
    .copied()
    .collect();

// Map and sum
let sum: i32 = numbers
    .iter()
    .map(|x| x * x)
    .sum();

๐Ÿ—๏ธ Project Ideas by Difficulty

Beginner

  • Temperature converter
  • Simple calculator
  • Word counter
  • File reader
  • Basic CLI tools

Intermediate

  • Web server with Actix or Axum
  • Database integration
  • JSON API
  • Command-line application with clap
  • Simple game

Advanced

  • Async web crawler
  • Database implementation
  • Compiler or interpreter
  • Network protocol implementation
  • Performance-critical system tools

๐Ÿ“š Additional Resources

You're all set to start your Rust journey! The language has a learning curve, but it's incredibly rewarding. Start with the guessing game, then work through the examples and exercises.

Happy coding! ๐Ÿฆ€

About

Learn Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages