1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
pub struct DoOnDrop { executor: Box<dyn FnMut()>, } impl DoOnDrop { pub fn new<F>(executor: F) -> Self where F: 'static + FnMut(), { Self { executor: Box::new(executor), } } } impl Drop for DoOnDrop { fn drop(&mut self) { (self.executor)(); } }