Session 02
Rust & ToolingSolana Dev Foundations
RUST WORKFLOW SPRINT
Work through curated Rust snippets to gain fluency for Solana development. Orientation, resources, and practice guidance included.
01
Orientation
Where to look
- Guide.txt and README.md contain schedule, problem statement, slides, and drive links.
- Contacts for help are listed in both files.
02
Rust snippet roadmap
Setup and basics
- Hello World (1_HelloWorld.rs): println! and formatting
- Variables & types (2_Variables.rs): immutability, mut, primitives
- Functions (3_Functions.rs): params, return types, multiple calls
- Conditionals (4_Conditionals.rs): if/else, expression returns
Control flow and collections
- Loops (5_Loops.rs): for ranges, while, infinite + break, chars()
- Arrays & vectors (6_Arrays.rs): fixed vs growable, push/pop, indexing
- Strings (7_Strings.rs): format!, casing, slicing, contains, CSV split
Data modeling
- Structs & methods (8_Structs.rs): constructors, impl, derived values
- Enums & matching (9_Enums.rs): exhaustive match, nested data
Reliability & safety
- Error basics (10_Error_Handling.rs): Option, Result, if let, unwrap_or
- Ownership & borrowing (11_Ownership.rs): moves, refs, slices, Copy
03
Concept spotlights
Expressions everywhere
- if blocks return values; branches must align types (4_Conditionals.rs)
- Implicit returns are last expressions without semicolon (3_Functions.rs)
Strings and slices
- format! builds Strings without moving inputs
- Slicing is byte based; examples use ASCII strings for safety (7_Strings.rs)
Enums with intent
- Success/Error variants carry typed data (9_Enums.rs)
- Exhaustive match enforces coverage; extend matches when adding variants
Ownership & borrowing
- Moves invalidate sources; scalars are Copy (11_Ownership.rs)
- Immutable vs mutable borrows; exclusive mut required
- String slices borrow without allocation
04
Practice plan
How to work the snippets
- Run each file via rustc your_file.rs && ./your_file (Windows: .\\your_file.exe) or drop into cargo new sandboxes.
- Tweak constants, add branches, extend enums to trigger compiler guidance.
- Intentionally break ownership rules (double mutable borrows) to feel the diagnostics.
- Stretch goals: add new Result error variants, add vector transformations, refactor to methods.
Stay in sequence; each snippet builds toward Anchor readiness.