Memory-Safe Programming with Rust
Class Duration
14 hours of live training delivered over 2-4 days to accommodate your scheduling needs.
Student Prerequisites
- Prior Rust programming experience equivalent to Rust Essentials
- Comfort writing functions, structs, enums, and basic generics
- Working understanding of how the stack and heap differ
Target Audience
Rust developers who can pass the borrow checker on simple code but struggle when ownership crosses thread or async boundaries, when self-referential data is involved, or when AI assistants suggest Rc<RefCell<T>> or Arc<Mutex<T>> reflexively. The course teaches how to make borrow-checker decisions deliberately and how to challenge AI-generated memory-management code.
Description
Most developers learn enough Rust to pass the borrow checker on simple code, then hit a wall: lifetimes that won't elide, structs that need to reference themselves, async tasks that need shared state, FFI boundaries that don't fit Rust's ownership rules. This course is the focused upskilling that gets developers across that wall. It works through Rust's memory model on the 2024 edition, smart pointer types and their actual costs, interior mutability, self-referential structures with Pin and helper crates, and concurrent ownership patterns. AI coding assistants are excellent at suggesting Rc<RefCell<T>> and Arc<Mutex<T>> for any borrow-checker error; this course teaches how to recognize when those suggestions are right and when they're hiding a design problem.
Learning Outcomes
- Explain Rust's memory model precisely: stack, heap, ownership, borrowing, and lifetimes.
- Read borrow-checker errors fluently and fix them without reflexively reaching for
Rc,RefCell, orunsafe. - Choose the right smart pointer (
Box,Rc,Arc,Cell,RefCell,Mutex,RwLock) for each situation. - Build self-referential structures safely using
Pinand pattern-appropriate crates. - Reason about ownership across async boundaries and thread boundaries.
- Audit AI-suggested memory-management code: when
Arc<Mutex<T>>is appropriate and when it's masking a design problem. - Identify when
unsafeis genuinely needed and how to wrap it in a safe abstraction.
Training Materials
All students receive comprehensive courseware covering all topics in the course. Courseware is distributed via GitHub in the form of documentation and extensive code samples. Students practice the topics covered through challenging hands-on lab exercises, including a final lab that takes a piece of AI-generated Rust with overuse of Arc<Mutex<T>> and refactors it to use ownership properly.
Software Requirements
A free GitHub account, the latest stable Rust toolchain installed via rustup (Rust 1.95+ on the 2024 edition), Visual Studio Code or another supported editor with the rust-analyzer extension, and an AI coding assistant of choice (GitHub Copilot, Cursor, or Claude Code) so the AI-review labs are realistic. A cloud-based environment can be provided if local installation is restricted.
Training Topics
How Memory Works
- How the OS views process memory
- Stack vs. heap allocation tradeoffs
- Manual memory management and its failure modes
- Garbage collection: where it costs you and where it doesn't
- Compile-time memory safety: Rust's approach and its limits
Variables, Bindings, and Data
- Variables vs. their data
- Mutability of bindings vs. mutability of data
- Move, copy, and clone semantics in practice
- Drop and
Dropimplementations - Variable shadowing and scoping nuances
The Rust Memory Model
- Ownership, borrowing, and references
- Lifetimes: elision, annotations, and higher-ranked bounds
- Shared XOR mutable: the rule and the reasons
- Stack-allocated vs. heap-allocated data
- The borrow checker as a productivity tool, not a hurdle
Reading Borrow-Checker Errors
- Common error patterns and what they actually mean
- Fixing errors by changing data shape vs. by adding indirection
- When AI assistants point you the wrong way and how to spot it
Smart Pointers
- What smart pointers actually are
Box<T>: heap allocation and trait objectsRc<T>andWeak<T>: single-threaded shared ownershipArc<T>: thread-safe shared ownership- Cost models: when each one is overkill
Interior Mutability
Cell<T>forCopytypesRefCell<T>and runtime borrow checkingMutex<T>andRwLock<T>for synchronized mutationOnceCell,OnceLock, and lazy initialization- Thread-safety implications of each
Self-Referential Structures
- Why naive self-references don't work in Rust
Pinand!Unpintypes- Using
ouroborosand similar crates pragmatically - Patterns that avoid self-reference entirely (indices into arenas)
Memory Safety Across Boundaries
- Ownership across async boundaries:
Send,Sync, and'static - Sharing state in Tokio tasks
- Auditing FFI boundaries for soundness
- A short tour of
unsafeand its rules
AI-Assisted Memory-Management Review
- Common AI failure modes: reflexive
Arc<Mutex<T>>, gratuitousBox, hidden clones - Prompting AI assistants for borrow-checker fixes that don't add cost
- A live review lab: take an AI-generated module and refactor it for proper ownership
- Course wrap-up and recommended next courses