summary refs log tree commit diff stats
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs22
1 files changed, 22 insertions, 0 deletions
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<F> InvalidContextError<F> {
     }
 }
 
+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<HookHandle<'_, '_>>) {
+    ///     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() {