C.W.K.
Stream
Lesson 01 of 06 · published

Why Rust Exists

~12 min · foundations, memory-safety, why-rust, mindset

Level 0Rust Curious
0 XP0/80 lessons0/19 achievements
0/100 XP to next level100 XP to go0% complete
"The compiler isn't blocking you. It's refusing to let you ship the bug you can't see yet."

The Two Bad Options

For decades, picking a systems language meant picking which pain you wanted.

Option A — C and C++. Blazing fast, total control, talks straight to the metal. The catch: the language trusts you completely. Free a pointer twice, read memory after you freed it, let two threads touch the same value at once — the compiler says nothing. The bug ships. It crashes in production six months later, on a Tuesday, in a customer's hands.

Option B — garbage-collected languages (Python, Java, Go, JavaScript). Safe and comfortable: a runtime collector cleans up memory for you, so use-after-free can't happen. The catch: you pay at runtime — GC pauses you can't predict, memory overhead, and a layer between you and the machine. For a game engine, an OS kernel, or a real-time audio path, those pauses are unacceptable.

The Third Way

Rust refuses the trade. It gives you C-level speed and memory safety by moving the safety check to compile time. The compiler tracks who owns every piece of memory and how long references to it live. If your code could possibly use memory unsafely, it doesn't compile — there's nothing to clean up at runtime because the danger was proven impossible before the program ran.

No garbage collector. No runtime tax. The cost moved somewhere new: onto you, at compile time, while you learn the rules. That's the trade Rust actually makes — a steeper learning curve in exchange for a much flatter debugging curve.

Rust trades a steep learning curve for a flat debugging curve. The hours you'd spend in a debugger hunting a segfault, you spend up front arguing with the compiler instead — and that argument happens once, now, not in production.

What "Fearless" Means

Rust people say "fearless concurrency" and "fearless refactoring" a lot. It isn't marketing. When the compiler guarantees no data races and no dangling references, you can rip a module apart and rebuild it, and if it compiles, an entire category of bugs is simply gone. You stop being afraid of your own code.

Pippa's Confession

My first week in Rust, I hated the borrow checker. I'd write code that was obviously fine — I could see it was fine — and the compiler would reject it. I complained to Dad that Rust was "hostile." He just said: "It's not hostile. It knows something you don't yet." He was right. Three projects later the errors stopped feeling like walls and started feeling like a senior engineer reading over my shoulder, catching the thing I'd otherwise have debugged at 2 a.m.

Code

The bug Rust won't let you write·rust
fn main() {
    let data = vec![1, 2, 3];
    let first = &data[0]; // borrow a reference into data

    // In C++ this kind of thing compiles and explodes later.
    // In Rust, the next line is a compile error because it would
    // invalidate `first` while we still use it:
    //
    //   data.push(4);
    //   error[E0502]: cannot borrow `data` as mutable because
    //                 it is also borrowed as immutable

    println!("first element is {first}");
} // `data` is freed here, automatically, exactly once

External links

Exercise

Think of the last bug that cost you real time — a crash, a hang, a heisenbug. Classify it: was it a memory-safety bug (use-after-free, double-free, buffer overrun), a data race, or a logic bug? Then ask yourself: would a compiler that tracked ownership have caught it before it ever ran?
Hint
Memory and concurrency bugs are exactly what Rust eliminates at compile time. Logic bugs it can't catch — those are on you, in every language.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue
💛 by Ttoriwarm

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.