Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Example Code

โค้ดตัวอย่างที่สามารถ clone และรันได้เลย


📦 วิธีใช้

# Clone repository
git clone https://github.com/premix-kernel/rust-tutorial.git
cd rust-tutorial

# รันตัวอย่าง
cargo run --example <name>

📋 รายการ Examples

Exampleบทคำอธิบาย
hello_world1-4ตัวแปร, ฟังก์ชัน, Control Flow
ownership5Move, Clone, Borrowing, Slices
structs_enums6-7Structs, Methods, Enums, Match
collections8Vec, String, HashMap
error_handling9Result, ?, unwrap_or
generics_traits10Generics, Traits, Bounds
iterators13Closures, map, filter, fold
smart_pointers14Box, Rc, RefCell, Weak
concurrency15Threads, Channels, Mutex
async_await16async/await, join!, spawn
web_server19Axum REST API

🚀 ตัวอย่างคำสั่ง

# Hello World
cargo run --example hello_world

# Ownership (สำคัญมาก!)
cargo run --example ownership

# Web Server (เปิด http://localhost:3000)
cargo run --example web_server

📝 โครงสร้างไฟล์

examples/
├── hello_world.rs       # บทที่ 1-4
├── ownership.rs         # บทที่ 5
├── structs_enums.rs     # บทที่ 6-7
├── collections.rs       # บทที่ 8
├── error_handling.rs    # บทที่ 9
├── generics_traits.rs   # บทที่ 10
├── iterators.rs         # บทที่ 13
├── smart_pointers.rs    # บทที่ 14
├── concurrency.rs       # บทที่ 15
├── async_await.rs       # บทที่ 16
└── web_server.rs        # บทที่ 19

✨ Output ตัวอย่าง

hello_world

🦀 สวัสดี Rust!
Hello, World!

📝 ตัวอย่างตัวแปร:
Name: Rustacean
Age: 25
Is Learning: true

ownership

🦀 Ownership Demo

1️⃣ Move:
s2 = hello

2️⃣ Clone:
s3 = world, s4 = world

3️⃣ Copy:
x = 5, y = 5

👉 กลับหน้า Appendix