Rust is a systems programming language created by Mozilla in 2010, now stewarded by the Rust Foundation, designed to provide C-level performance while guaranteeing memory safety without a garbage collector through its ownership system. Used across operating systems, embedded devices, web services, blockchain infrastructure, and safety-critical systems, Rust prevents entire classes of bugs at compile time through its borrow checker. Understanding Rust isn't just about syntaxβit's about embracing ownership thinking, recognizing when to use references versus smart pointers, and leveraging the type system to eliminate runtime errors before deployment.
What This Cheat Sheet Covers
This topic spans 26 focused tables and 303 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: Primitive Types
| Type | Example | Description |
|---|---|---|
let x: i32 = -42; | β’ Signed integers of 8, 16, 32, 64, 128 bits β’ i32 is default for integer literals. | |
let x: u8 = 255; | β’ Unsigned integers from 0 to maximum β’ u8 commonly used for byte data. | |
let idx: usize = 0; | β’ Pointer-sized integers β’ usize required for indexing arrays and collections. | |
let pi: f64 = 3.14159; | β’ 32 and 64-bit floating point β’ f64 is default for literals, same speed as f32 on modern CPUs. | |
let flag = true; | β’ Boolean with values true or falseβ’ 1 byte in size; condition must be explicit bool. | |
let c = 'z'; | β’ Unicode scalar value β’ 4 bytes, represents any valid Unicode code point. | |
let t = (1, "hello"); | β’ Fixed-size heterogeneous collection β’ accessed via pattern matching or dot notation like t.0. |