Rust Tutorial“, almost always they mean:
A beginner-friendly guide to learn the Rust programming language (not the video game called Rust)
Rust (the programming language) is a modern, super-fast, super-safe systems programming language created by Mozilla (first versions around 2010, became very popular ~2015–2025).
People use Rust today to write:
- Web servers (like parts of Discord, Dropbox)
- Blockchain / crypto stuff
- Game engines
- Operating system kernels
- CLI tools
- Embedded devices
- Anything where C/C++ was used before, but they want safety + speed
Okay, now let’s act like a real teacher and start from zero — slowly and with examples.
Step 1: What makes Rust special? (The 3 big promises)
Imagine I tell you three magical rules Rust enforces:
- Memory safety without garbage collector → No null pointer crashes, no use-after-free, no buffer overflow (like 70–80% of serious security bugs disappear)
- Fearless concurrency → You can use many threads and Rust compiler stops most data races at compile time
- Zero-cost abstractions → You write high-level beautiful code → it runs almost as fast as low-level C
Because of these, many big companies switched parts of their code to Rust: Microsoft, AWS, Google, Meta, Discord, Cloudflare, etc.
Step 2: Hello World — Your first Rust program
First you need Rust installed.
Go here → https://www.rust-lang.org/tools/install Run this command (works on Linux, macOS, Windows with WSL or Git Bash):
|
0 1 2 3 4 5 6 |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh |
After installation, check:
|
0 1 2 3 4 5 6 7 |
rustc --version cargo --version |
You should see something like rustc 1.85.0 or newer (in 2026 probably 1.90+).
Now create first program:
|
0 1 2 3 4 5 6 7 |
cargo new hello_rust cd hello_rust |
Open src/main.rs and write:
|
0 1 2 3 4 5 6 7 8 9 |
fn main() { println!("Namaste! Hello from Rust! 🚀"); println!("Today is {}, and I'm learning Rust!", "26th February 2026"); } |
Run it:
|
0 1 2 3 4 5 6 |
cargo run |
Output:
|
0 1 2 3 4 5 6 7 |
Namaste! Hello from Rust! 🚀 Today is 26th February 2026, and I'm learning Rust! |
cargo run = compile + run Very convenient!
Step 3: Variables & Data Types (very important in Rust)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
fn main() { // immutable by default (cannot change!) let name = "Webliance"; // type guessed: &str let age = 25; // guessed: i32 let height = 5.9; // guessed: f64 let is_learning = true; // bool // Want to change? Use mut let mut score = 10; score = score + 5; // OK // Constants (always uppercase, type must be written) const PI: f64 = 3.14159; const MAX_USERS: u32 = 100_000; // underscore = nice separator println!("Name: {}, Age: {}, Score now: {}", name, age, score); } |
Important rules you will love/hate at first:
- Variables are immutable by default → very good for safety
- You must write mut when you want to change them
Step 4: Ownership – The famous Rust concept (Chapter 4 in The Book)
This is where most beginners go “😱 what??”
Simple analogy:
Every value in Rust has one owner.
When owner goes out of scope → value is dropped (memory freed automatically).
You can move ownership or borrow it.
Example – move:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 |
fn main() { let s1 = String::from("Hyderabad"); let s2 = s1; // ← ownership moved to s2 // println!("{}", s1); // ERROR! s1 no longer owns the value println!("{}", s2); // Works — s2 is now owner } |
Example – borrow (very common):
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
fn main() { let s = String::from("Hello from Telangana"); print_length(&s); // borrow (no move) print_length(&s); // can borrow again! println!("Still have: {}", s); // s still exists } fn print_length(text: &String) { // & = reference (borrow) println!("Length is {} characters", text.len()); } |
Rules (compiler enforces them):
- At any time, you can have either:
- One mutable reference (&mut)
- OR many immutable references (&)
- But never both at the same time
This stops data races at compile time — magic!
Step 5: Small but real example — Number Guessing Game
This is the classic example from official Rust Book:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
use std::io; use std::cmp::Ordering; use rand::Rng; fn main() { println!("Guess the number between 1 and 100!"); let secret_number = rand::thread_rng().gen_range(1..=100); loop { println!("Please input your guess:"); let mut guess = String::new(); io::stdin() .read_line(&mut guess) .expect("Failed to read line"); let guess: u32 = match guess.trim().parse() { Ok(num) => num, Err(_) => { println!("Please type a number!"); continue; } }; println!("You guessed: {}", guess); match guess.cmp(&secret_number) { Ordering::Less => println!("Too small!"), Ordering::Greater => println!("Too big!"), Ordering::Equal => { println!("You win! 🎉"); break; } } } } |
Add dependency in Cargo.toml:
|
0 1 2 3 4 5 6 7 |
[dependencies] rand = "0.8.5" |
Then cargo run — enjoy!
Where should you learn properly? (2026 recommendation)
Best free path in 2025–2026:
- The Rust Book (official, free, best quality) → https://doc.rust-lang.org/book/
- While reading — watch Let’s Get Rusty YouTube videos → Same chapter order, very clear explanations
- After ~Chapter 6 do small projects:
- CLI tool (clap crate)
- Tiny web server (axum or actix-web)
- File reader / JSON parser
- Extra good resources:
- Rust by Example → https://doc.rust-lang.org/rust-by-example/
- Comprehensive Rust (Google) → https://google.github.io/comprehensive-rust/
- Rustlings (small exercises) → https://github.com/rust-lang/rustlings
Start slow. Rust feels hard for 1–3 weeks → then suddenly clicks and you fall in love 😄
Any chapter or concept you want me to explain next in detail? Ownership again? Structs? Enums? Error handling? Lifetimes? Just tell me — I’m your Rust teacher today! 🚀
