From 11267ce31034f800e033ef98eff8b5979e6e8cd1 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Sat, 16 Apr 2022 10:00:04 -0300 Subject: Add a method to inspect hook liveness --- src/lib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index f539a58..bff39e2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -395,6 +395,28 @@ impl InvalidContextError { } } +impl<'ph, 'f> HookHandle<'ph, 'f> where 'ph: 'f { + /// If this is a timer hook, returns whether the hook has expired. + /// + /// Otherwise, returns false. + /// + /// # Examples + /// + /// ```no_run + /// use hexchat_unsafe_plugin::{HookHandle}; + /// + /// /// Remove timers that have expired. + /// fn clean_up_timers(timers: &mut Vec>) { + /// timers.retain(|timer| { + /// !timer.expired() + /// }); + /// } + /// ``` + pub fn expired(&self) -> bool { + self.freed.get() + } +} + impl<'ph, 'f> Drop for HookHandle<'ph, 'f> where 'ph: 'f { fn drop(&mut self) { if self.freed.get() { -- cgit 1.4.1