Rust
Rust delivers C/C++-level performance while guaranteeing memory safety at compile time — without a garbage collector. Its ownership system tracks who is responsible for each value and when it's freed, catching whole categories of bugs (use-after-free, data races, null dereferences) before the program ever runs.
That safety comes with a famously steep learning curve: the borrow checker rejects code that would be unsafe, which feels like fighting the compiler at first and like a safety net once it clicks. It's the language of choice for systems programming, WebAssembly, embedded, game engines, and performance-critical services.
TL;DR
- Memory safety without garbage collection, enforced at compile time.
- Ownership & borrowing are the core model — and the main learning hurdle.
- No null — use
Option<T>; no exceptions — useResult<T, E>. - Fearless concurrency: the type system prevents data races at compile time.
- Cargo is the build tool, package manager, and test runner.
Quick Example
Borrowing lets a function read a value without taking ownership — the original stays usable:
Core Concepts
Variables & types
Ownership
Three rules: each value has one owner; there's only one owner at a time; when the owner goes out of scope, the value is dropped (freed). Assigning a non-Copy value moves it:
Borrowing
Reference a value without taking ownership — any number of immutable borrows (&T) or exactly one mutable borrow (&mut T) at a time:
This rule, enforced by the borrow checker, makes data races impossible at compile time.
Structs & enums
No null, no exceptions
Pattern matching
Error Handling
The ? operator propagates errors concisely; reserve panic! for truly unrecoverable bugs:
Crates like anyhow (applications) and thiserror (libraries) make custom errors ergonomic.
Collections & Iterators
Traits
Traits define shared behavior (like interfaces), with optional defaults:
Concurrency
Ownership makes concurrency fearless — the compiler rejects code that would race on shared data:
Threads also communicate via channels (std::sync::mpsc).
Async/await
Cargo & Testing
Best Practices
- Prefer
&stroverStringfor read-only parameters; lean on iterators (zero-cost). - Run
clippyandfmt; useVec::with_capacitywhen the size is known. - Avoid
.unwrap()in library code — returnResultand let callers decide. - Reach for
unsafeonly after profiling proves it necessary; enable LTO in release builds.
Essential crates
serde (serialization), tokio (async runtime), clap (CLI), anyhow/thiserror (errors), axum/actix-web (web), reqwest (HTTP client), rayon (data parallelism), chrono (time).
Comparison
See Go and Systems Programming.
Common Mistakes
.unwrap() everywhere
Fighting the borrow checker by cloning everything
FAQ
What makes Rust memory-safe without a garbage collector?
The ownership and borrowing rules, checked at compile time. The compiler knows exactly when each value is no longer used and inserts the cleanup, and its borrowing rules prevent use-after-free and data races — all without a runtime GC, so you keep predictable, C-class performance.
What is the ownership system?
A set of compile-time rules: every value has a single owner, ownership moves on assignment (so there's no aliased free), and values are dropped when their owner goes out of scope. Borrowing lets you reference values temporarily under strict rules. Together they replace both manual memory management and garbage collection.
Is the steep learning curve worth it?
For performance-critical, systems, embedded, or safety-sensitive work, yes — you get C-level speed with guarantees other systems languages can't offer, and far fewer runtime crashes. For typical CRUD web apps, a higher-level language is often more productive; Rust shines where correctness and performance both matter.
When should I choose Rust?
Systems programming, WebAssembly, embedded devices, game engines, and performance-critical services where you can't afford GC pauses or memory bugs. Pick a higher-level language when developer velocity matters more than raw performance and safety guarantees.
Related Topics
- Systems Programming — Rust's home turf
- WebAssembly — A major Rust target
- Memory Management — Ownership vs manual/GC
- Concurrency Patterns — Fearless concurrency
- Go — A gentler systems-adjacent option
- Axum — Building web services in Rust