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

 
 
 

Contributors

Languages