At the beginning, I only wanted to understand an article that was talking about aliasing XOR mutability and craft an async runtime from scratch. With some luck, this project would help me mix both ideas. According to Claude, not really, so I kept chatting with it to know what could help me understand the former and what could teach me the latter. In the end, I crafted some kind of curriculum. This repo reflects my learnings and projects.
As a do the project one by one, I review the the content. My progress are marked with a ---CURRENT PROGRESS--- so you can see what I already reviewed.
Goal: Master traits, generics, and trait-based API design
- Iterator Library (1 week)
- JSON Parser/Serializer (1-2 weeks)
Goal: Deep understanding of borrow checker, unsafe Rust, and manual memory management
- Arena Allocator (3-5 days)
- Malloc-like Allocator (1-2 weeks)
- Custom Smart Pointers (3-5 days)
Goal: Master async state machines, Pin, and cooperative concurrency
- Async/Await Runtime (2-3 weeks)
Goal: Master atomics, memory ordering, and lock-free data structures
- Lock-Free MPSC Queue (2-3 weeks)
---CURRENT PROGRESS---
- Basic Rust ownership and borrowing
- Comfortable with structs and enums
- Understand what traits are
- Basic generics syntax
- Master traits, generics, and associated types
- Understand zero-cost abstractions
- Learn trait-based API design
- Build composable, reusable code
What to Build:
- Core
MyIteratortrait withnext()method and amy_iter()for Vec - Adaptors:
map,filter,chain,zip,enumerate,take,skip - Consumers:
fold,any,position - Collectors:
collect()intoVecand custom containers
Key Learning Outcomes:
- Associated types vs generic parameters
- Zero-cost abstractions in practice
- Lifetime bounds on traits
impl Traitsyntax- Method chaining patterns
What Success Looks Like:
let result: Vec<_> = vec![0..10]
.my_iter()
.filter(|x| x % 2 == 0)
.map(|x| x * x)
.take(3)
.collect();What to Build:
SerializeandDeserializetraits- Support for primitives, structs, enums,
Vec,HashMap - Visitor pattern for deserialization
- Custom error types with proper error handling
Key Learning Outcomes:
- Trait bounds and
whereclauses - Blanket implementations
- The visitor pattern (critical for async later)
- Associated types for complex relationships
- Trait-based API design
What Success Looks Like:
#[derive(Serialize, Deserialize)]
struct Person {
name: String,
age: u32,
}
let json = to_json(&person)?;
let person: Person = from_json(&json)?;- ✅ Can write generic, composable APIs
- ✅ Understand trait bounds and associated types
- ✅ Know when to use static vs dynamic dispatch
- ✅ Comfortable with complex trait hierarchies
- ✅ Can design trait-based abstractions
Before Starting:
- "Programming Rust" 2nd Edition
- Chapter 11: Traits and Generics
- Chapter 13: Utility Traits
- Chapter 15: Iterators
While Building:
- "Rust for Rustaceans" by Jon Gjengset - Chapter 2: Types
- Study
serdesource code (after JSON parser first attempt) - "Rust Design Patterns" (https://rust-unofficial.github.io/patterns/)
- Completed Phase 0
- Comfortable with traits and generics
- Understand basic lifetimes
- Know what unsafe code is (high-level)
- Deep understanding of borrow checker motivation
- Master unsafe Rust fundamentals
- Understand aliasing XOR mutability viscerally
- Learn manual memory management
- Build smart pointers from scratch
What to Build:
- Bump allocator from contiguous buffer
- Type-safe allocation with lifetime bounds (
&'arena T) - Reset functionality (bulk deallocation)
- Interior mutability for bump pointer (
Cell<usize>)
Key Learning Outcomes:
- Lifetime parameters in depth
- Basic
unsafepointer arithmetic NonNull<T>usage- Why use-after-free is prevented by lifetimes
- Interior mutability patterns
What Success Looks Like:
let arena = Arena::new(1024);
let x = arena.alloc(42);
let y = arena.alloc(100);
// arena.reset(); // Would invalidate x and y - prevented by borrow checker!
println!("{} {}", x, y);What to Build:
- Free list management (linked list of free blocks)
alloc()andfree()operations- Coalescing adjacent free blocks
- First-fit or best-fit allocation strategy
- Proper alignment handling
Key Learning Outcomes:
- THE core aliasing XOR mutability lesson
- Complex pointer manipulation in unsafe code
- Maintaining invariants manually
- Why the borrow checker rules exist
- Memory corruption patterns (and how to avoid them)
What Success Looks Like:
let allocator = Allocator::new(4096);
let ptr1 = allocator.alloc(Layout::new::<i32>());
let ptr2 = allocator.alloc(Layout::new::<String>());
allocator.free(ptr1);
let ptr3 = allocator.alloc(Layout::new::<i32>()); // Reuses ptr1's blockWhat to Build:
MyBox<T>- owned heap allocationMyRc<T>- reference countingMyWeak<T>- weak references to break cycles- (Optional)
MyArc<T>- thread-safe reference counting
Key Learning Outcomes:
NonNull<T>andPhantomData<T>- Manual
Dropimplementation - Deref coercion
- Reference counting implementation
- Building on malloc knowledge
SendandSynctraits (forArc)
What Success Looks Like:
let x = MyRc::new(42);
let y = MyRc::clone(&x);
assert_eq!(MyRc::strong_count(&x), 2);
drop(y);
assert_eq!(MyRc::strong_count(&x), 1);- ✅ Deeply understand why borrow checker rules exist
- ✅ Comfortable writing and reviewing unsafe code
- ✅ Can reason about lifetimes and ownership at low level
- ✅ Understand smart pointer internals
- ✅ Know when unsafe is necessary and how to use it safely
Before Starting:
- "The Rustonomicon" (https://doc.rust-lang.org/nomicon/)
- Ownership, Lifetimes, Working with Uninitialized Memory
- "Computer Systems: A Programmer's Perspective" - Chapter 9 (Virtual Memory)
While Building:
- "The Garbage Collection Handbook" - Chapters on manual memory management
- "Rust for Rustaceans" - Chapter 2 (Types), Chapter 8 (Unsafe)
- "Programming Rust" - Chapter 13 (Smart Pointers)
- Completed Phase 1
- Comfortable with unsafe Rust
- Deep understanding of ownership and lifetimes
- Familiar with trait-based abstractions from Phase 0
- Understand async state machines
- Master
Pinand self-referential structs - Learn cooperative concurrency model
- Build async abstractions from scratch
- Understand
Wakersystem
Week 1: Foundation
- Task queue with basic executor
- Implement simple
Futuretrait - Understand
Polland state machines - Manual async state machines (before using
async fn)
Week 2: Waker System
- Implement
WakerandContext - Task spawning and scheduling
- Basic async I/O (timers)
- Understanding ownership transfer across poll calls
Week 3: Polish
- Joining tasks and collecting results
- Error propagation in async context
- Basic async network I/O
- Multiple tasks with priority scheduling
Key Learning Outcomes:
- How
async fntransforms into state machines Pin<&mut T>and why it's needed- Self-referential structs problem
Wakercloning and ownership- Single-threaded async patterns
- The difference between concurrency and parallelism
What Success Looks Like:
async fn fetch_data(url: &str) -> Result<String, Error> {
let response = http_get(url).await?;
Ok(response)
}
let runtime = Runtime::new();
runtime.block_on(async {
let result = fetch_data("http://example.com").await;
println!("{:?}", result);
});- ✅ Understand async state machines deeply
- ✅ Know when and how to use
Pin<&mut T> - ✅ Can implement custom
Futuretypes - ✅ Understand
Wakersystem internals - ✅ Can build async abstractions
- ✅ Understand cooperative vs preemptive concurrency
Before Starting:
- "Asynchronous Programming in Rust" (https://rust-lang.github.io/async-book/) - Read cover-to-cover
- "Rust for Rustaceans" - Chapter 9: Asynchronous Programming
While Building:
- "Programming Rust" - Chapter 20: Asynchronous Programming
- Rust async/await RFC 2394
- Study
tokiosource code after first implementation
- Completed Phase 2
- Deep understanding of ownership
- Comfortable with unsafe Rust
- Understand cooperative concurrency from async
- Ready for preemptive concurrency
- Master atomic operations and memory ordering
- Understand where borrow checker can't help
- Learn lock-free data structures
- Handle concurrent aliasing manually
- Understand memory reclamation strategies
Week 1: Lock-Based Foundation
- Build multi-threaded queue with
Mutex<VecDeque<T>> - Understand the baseline performance
- See where locks cause contention
- Multiple producer threads pushing, one consumer popping
Week 2: Lock-Free SPSC
- Single-producer, single-consumer lock-free queue
- Introduction to
AtomicPtrandAtomicUsize - Basic memory ordering (
Relaxed,Acquire,Release) - No memory reclamation issues (simpler case)
Week 3: Lock-Free MPSC
- Multi-producer, single-consumer lock-free queue
- Compare-and-swap loops
- ABA problem and solutions
- Epoch-based memory reclamation
- Extensive testing for race conditions
Key Learning Outcomes:
- Memory ordering (
Acquire,Release,SeqCst,Relaxed) - Where the borrow checker fundamentally cannot help
- ABA problem (pointer recycling hazard)
- Memory reclamation in concurrent context
- Concurrent aliasing patterns
- Testing concurrent code
- Performance profiling under contention
What Success Looks Like:
let queue = MPSCQueue::new();
let queue_ref = Arc::new(queue);
// Multiple producers
for i in 0..4 {
let q = queue_ref.clone();
thread::spawn(move || {
for j in 0..1000 {
q.push(i * 1000 + j);
}
});
}
// Single consumer
while let Some(item) = queue_ref.pop() {
println!("{}", item);
}- ✅ Complete mastery of Rust fundamentals
- ✅ Understand memory ordering deeply
- ✅ Can write production-quality concurrent code
- ✅ Know when and how to use unsafe correctly
- ✅ Understand lock-free algorithm trade-offs
- ✅ Can reason about concurrent memory safety
Before Starting:
- "C++ Concurrency in Action" - Chapter 7 (Lock-Free Data Structures) - CRITICAL
- "The Art of Multiprocessor Programming" - Chapters 10-11
While Building:
- "Rust Atomics and Locks" by Mara Bos
- Michael & Scott paper: "Simple, Fast, and Practical Non-Blocking and Blocking Concurrent Queue Algorithms"
- Study
crossbeamsource code (epoch-based reclamation)
- "Rust for Rustaceans" by Jon Gjengset
- "Programming Rust" 2nd Edition
- "Rust Atomics and Locks" by Mara Bos
- "C++ Concurrency in Action" by Anthony Williams
- "The Art of Multiprocessor Programming" by Herlihy & Shavit
- "Computer Systems: A Programmer's Perspective" (CS:APP)
- "The Garbage Collection Handbook"
- The Rustonomicon: https://doc.rust-lang.org/nomicon/
- Async Book: https://rust-lang.github.io/async-book/
- Rust Design Patterns: https://rust-unofficial.github.io/patterns/
Total Duration: 9-14 weeks (2-3.5 months)
- Phase 0: 2-3 weeks
- Phase 1: 2-3 weeks
- Phase 2: 2-3 weeks
- Phase 3: 2-3 weeks
- Contributing to major Rust projects (tokio, rust-analyzer, servo)
- Building production systems programming projects
- Reviewing unsafe code confidently
- Teaching others Rust fundamentals
- Database Storage Engine (B-tree or LSM-tree)
- JIT Compiler
- Operating System Component
- Custom Garbage Collector