use log::trace;
use std::any::type_name;

pub struct OnDrop<F: FnMut()> {
    func: F,
}

pub fn on_drop<F: FnMut()>(func: F) -> OnDrop<F> {
    trace!("on_drop<F={}>()", type_name::<F>());
    OnDrop { func }
}

impl<F: FnMut()> Drop for OnDrop<F> {
    fn drop(&mut self) {
        trace!("OnDrop<F={}>::drop()", type_name::<F>());
        (self.func)();
    }
}
