# Rust Language Reference
## Languages — The Codex Coding
**URL:** https://thecodex.expert/coding/languages/rust/
**Type:** language-reference | **Confidence:** high | **Last verified:** 2026-06-01

## CANONICAL DEFINITION
Rust is a systems programming language that achieves memory safety without a garbage collector through an ownership system enforced at compile time — eliminating use-after-free, null pointer dereferences, buffer overflows, and data races while compiling to native machine code with no runtime overhead.

## QUICK FACTS
- **Released:** May 2015 (1.0); created by Graydon Hoare at Mozilla Research
- **Version:** Rust 1.x (stable channel, 6-week release cycle)
- **Typing:** Static, strong, inferred
- **Execution:** Native compiled (LLVM backend)
- **Memory:** Ownership system — automatic drop at scope end; no GC, no manual free
- **Concurrency:** Fearless — Send + Sync traits enforce thread safety at compile time

## OWNERSHIP RULES (3 rules, enforced at compile time)
1. Each value has exactly one owner
2. When the owner goes out of scope, the value is dropped (freed)
3. Assignment MOVES ownership (unless type implements Copy)

## BORROWING RULES
- Immutable references (&T): unlimited, but cannot coexist with mutable ref
- Mutable references (&mut T): exactly ONE at a time, no other refs active
- References must always be valid (no dangling pointers — enforced by borrow checker)

## CRITICAL NOTES
- **No GC but automatic memory management** — Drop trait frees at scope end; neither manual nor GC
- **Borrow checker errors = compiler protecting you** — "value moved" etc. prevent real runtime bugs
- **Rust futures are LAZY** — calling async fn returns a Future; needs runtime (Tokio) to execute
- **unsafe unlocks exactly 5 things**: raw pointers, unsafe fn calls, mutable statics, unsafe traits, union fields
- **Copy types** (integers, bool, char, &T): copied on assignment | **Move types** (String, Vec, Box): moved
- **Option<T>** = Some(T) or None — replaces null | **Result<T,E>** = Ok(T) or Err(E) — replaces exceptions

## KEY TYPES
- Scalar: i8/i16/i32/i64/i128/isize, u8..u128/usize, f32/f64, bool, char
- Compound: tuples (T, U), arrays [T; N] (fixed), slices [T] (dynamic view)
- Heap: String (owned), &str (borrowed slice), Vec<T>, Box<T>, Rc<T>, Arc<T>
- Error: Option<T> (nullable), Result<T, E> (fallible operations)
- Concurrency: Mutex<T>, RwLock<T>, Arc<T>, mpsc::channel

## CARGO
- `cargo new name` — create project
- `cargo build` — compile
- `cargo run` — compile + run
- `cargo test` — run tests
- `cargo doc` — generate docs
- `Cargo.toml` — dependencies | `Cargo.lock` — locked versions
- Package registry: crates.io (150,000+ crates)

## NOTABLE DEPLOYMENTS
- Linux kernel (since 6.1, December 2022)
- Windows NT kernel driver infrastructure (Microsoft, 2023+)
- Firefox, Cloudflare Workers, AWS Firecracker, Discord, Figma, Android

## FORMAL VERIFICATION
- RustBelt (Jung et al., POPL 2018): mechanized proof in Iris/Coq that Rust's type system is sound
- Proved: if rustc accepts a program, it is memory-safe and data-race-free (assuming no unsafe)

## SOURCES
- The Rust Programming Language (book): doc.rust-lang.org/book/
- Rust Reference: doc.rust-lang.org/reference/
- RustBelt: dl.acm.org/doi/10.1145/3158154

*The Codex Coding — thecodex.expert/coding/ — Free forever — Mumbai, India*
