Rust
Rust cheat sheet covering ownership, borrowing, lifetimes, pattern matching, traits, async/await, and systems programming examples.
Getting Started
Installation, setup, and basics
Installation & Setup
Install Rust and create your first project
Hello World
Basic Rust program structure
Variables & Types
Variable declarations, mutability, and basic types
Variables & Mutability
Declaring variables and understanding mutability
Basic Data Types
Scalar and compound types in Rust
Ownership & Borrowing
Rust's unique ownership system for memory safety
Ownership Rules
Understanding Rust's ownership model
Borrowing & References
Using references to avoid moving values
Control Flow
Conditionals, loops, and pattern matching
If Expressions
Conditional branching in Rust
Loops
Different types of loops in Rust
Pattern Matching
Powerful pattern matching with match
Functions & Closures
Function definitions, parameters, and closures
Function Basics
Defining and calling functions
Closures
Anonymous functions with environment capture
Structs & Enums
Custom data types and algebraic data types
Structs
Creating custom data types with structs
Enums
Algebraic data types with enums
Methods & Impl Blocks
Adding methods to structs and enums
Traits
Defining shared behavior with traits
Defining & Implementing Traits
Create traits, implement them, and use trait bounds
Common Traits & Derive
Standard library traits and the derive macro
Generics
Generic types, functions, and constraints
Generic Functions & Types
Parameterize functions, structs, and enums over types
Lifetimes
Lifetime annotations for references
Lifetime Annotations
Annotate lifetimes to help the borrow checker
Error Handling
Handling errors with Result and Option
Result Type
Error handling with Result<T, E>
Option Type
Handling optional values with Option<T>
Collections
Vectors, strings, and hash maps
Vectors
Dynamic arrays with Vec<T>
Strings
String manipulation and UTF-8 text
Hash Maps
Key-value storage with HashMap
Iterators
Iterator adaptors and consuming methods
Iterator Methods
Chaining iterator adaptors and collectors
Smart Pointers
Heap allocation and reference counting
Box, Rc & RefCell
Heap allocation, shared ownership, and interior mutability
Concurrency
Threads, channels, and shared state
Threads & Channels
Spawn threads and communicate with message passing
Modules & Cargo
Code organization and package management
Modules & Visibility
Organize code with modules and control visibility
Cargo Essentials
Package management and project commands
Testing
Unit tests, integration tests, and assertions
Writing Tests
Unit tests, assertions, and test organization