use std::sync::Arc; crate::utils::ids::id_gen!(hooks_id); /// Unique hook identifier used to unregister commit/descruction hooks #[derive(Debug, Clone, Eq, PartialEq)] pub struct HookId(Arc); pub(crate) struct Hook { pub id: HookId, pub cb: Arc, } impl std::fmt::Debug for Hook { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("Hook") .field("id", &self.id) .finish_non_exhaustive() } } impl Clone for Hook { fn clone(&self) -> Self { Self { id: self.id.clone(), cb: self.cb.clone(), } } } impl Hook { pub fn new(cb: Arc) -> Self { Self { id: HookId(Arc::new(InnerId::new())), cb, } } } #[derive(Debug, Eq, PartialEq)] struct InnerId(usize); impl InnerId { fn new() -> Self { Self(hooks_id::next()) } } impl Drop for InnerId { fn drop(&mut self) { hooks_id::remove(self.0); } }