Drop
When a data type has the Drop trait, the program will call the drop function for values of that type immediately before their lifetimes end. That's how Rc, Mutex, RefCell, and so on are able to keep track of how many borrows their contained value has.
The drop function is called before the data value's lifetime ends, so we don't have to worry about it being an invalid reference. Also, we don't have to worry about manually cleaning up the contained values for our data type, because they will be automatically dropped themselves after our drop function is finished. All we need to do is handle whatever special case led us to implement Drop in the first place.
We can't directly call the drop function, because that would be an extremely good ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access