Slug: iter-custom-01 · Paired reading: Chapter 9
Prompt
Implement struct Countdown { remaining: u32 } with Countdown::new(n) and
impl Iterator<Item = u32> that yields n, n-1, …, 1 then None.
Yield nothing when n == 0.
Contract
- After exhaustion, further
nextcalls returnNone(fused-by-construction) - Store progress in the struct fields — do not hide the state machine in a range adapter inside
next
Predict first
Where does the current value live between next calls?
Rust angle
Custom iterators are state machines: fields remember progress; next advances them.