1. impl Drop for List {
    2. fn drop(&mut self) {
    3. let mut cur_link = mem::replace(&mut self.head, Link::Empty);
    4. // `while let` == "do this thing until this pattern doesn't match"
    5. while let Link::More(mut boxed_node) = cur_link {
    6. cur_link = mem::replace(&mut boxed_node.next, Link::Empty);
    7. // boxed_node goes out of scope and gets dropped here;
    8. // but its Node's `next` field has been set to Link::Empty
    9. // so no unbounded recursion occurs.
    10. }
    11. }
    12. }