Deref and again create a &mut reference starting from a &mut reference

Yeah. They're just using the IntoIterator implementation on &mut Vec<T> to remove all the items from the collection and let them be destroyed.

You could also implement it as while let Some(item) = self.pop() { drop(item); } or for item in self.drain(..) { drop(item); }[1], they're all different ways of achieving the same thing.


  1. The drop() call wasn't really necessary here. I just added it to make it explicit that we're only removing items so they can be destroyed. ↩︎

1 Like