Rust Notes — Module 1

Rust Notes — Module 1: The Basics & Ownership 1. Why Rust? Language Memory Management Cost C Manual (malloc/free) Unsafe — use-after-free, double-free, null deref Go Garbage Collector Safe, but runtime overhead (GC pauses) Rust Ownership system (compiler-enforced) Safe + zero runtime cost Rust’s core promise: memory safety at compile time, with no garbage collector. 2. Variables & Mutability Variables are immutable by default in Rust. You must explicitly opt into mutation with mut. let x = 5; // immutable — cannot be reassigned // x = 6; // ❌ compile error let mut y = 5; // mutable y = 6; // ✅ fine Shadowing You can redeclare a variable with let in the same scope — this is called shadowing: ...

March 17, 2026 · 6 min

Rust Notes — Module 2

Rust Notes — Module 2: Borrowing & References 1. The Problem Ownership Alone Creates If ownership always moves, passing values to functions becomes painful — you lose access to the value after the call: fn print_string(s: String) { println!("{}", s); } // s is dropped here fn main() { let s = String::from("hello"); print_string(s); // println!("{}", s); // ❌ s was moved into print_string, gone! } You’d have to clone everything or return ownership back — both are tedious. Borrowing solves this. ...

March 17, 2026 · 6 min