Rust Quick Reference
Rust essentials: variables, ownership and borrowing, strings, vectors, structs, enums, matching, traits, errors and Cargo.
6 sections · 34 snippets · updated Oct 14, 2026
Click any snippet to copy it.
Basics
Programs and variables.
TaskCode
- Hello world
- Variables
- Types
- Print / format
- Convert
Ownership & borrowing
Rust's memory model.
TaskCode
- Move
- Clone
- Borrow (read)
- Borrow (write)
- Lifetimes
Strings & collections
Text, vectors and maps.
TaskCode
- String / &str
- Append
- Vector
- Iterate
- Map / filter / collect
- Sum
- Reverse
- HashMap
- Count with entry
Structs, enums & matching
Data types.
TaskCode
- Struct
- Methods
- Enum with data
- Match
- If let
- Trait
Errors
Option and Result.
TaskCode
- Option
- Result
- Propagate with ?
- Handle
- Panic
Cargo
Build tool and packages.
TaskCode
- New project
- Run / build / test
- Add a crate
- Check / lint / format