summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2022-04-17 19:37:34 -0300
committerSoniEx2 <endermoneymod@gmail.com>2022-04-17 19:37:34 -0300
commit6745da74000158e02bdf049e37ceec29e546827f (patch)
tree78b1d7cbaf15f9410e20167e5c9be78b497361cb /src
parent01c6e6c4b6c81cfe55a543598daa9b7b8fb331e0 (diff)
Restore for_entry_mut
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs56
1 files changed, 29 insertions, 27 deletions
diff --git a/src/lib.rs b/src/lib.rs
index fb207aa..012846d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -590,33 +590,35 @@ impl<'ph> PluginHandle<'ph> {
         }
     }
 
-    ///// Operates on a virtual plugin.
-    /////
-    ///// # Examples
-    /////
-    ///// ```no_run
-    ///// use hexchat_unsafe_plugin::{PluginHandle};
-    /////
-    ///// fn contexts_can_be_passed_in(ph: &mut PluginHandle<'_>) {
-    /////     let ctx = ph.get_context();
-    /////     let mut vplug = ph.plugingui_add("foo", "bar", "baz", "qux");
-    /////     ph.for_entry_mut(&mut vplug, |ph| {
-    /////         ph.set_context(&ctx);
-    /////     });
-    ///// }
-    ///// ```
-    //pub fn for_entry_mut<'eh, F, R>(&mut self, entry: &mut PluginEntryHandle<'ph>, f: F) -> R where F: FnOnce(&mut PluginHandle<'eh>) -> R, 'ph: 'eh {
-    //    // we're doing something kinda (very) weird here, but this is the only
-    //    // way to get and set pluginprefs for virtual plugins.
-    //    // this should be sound.
-    //    let data = self.data;
-    //    let info = self.info;
-    //    let contexts = Rc::clone(&self.contexts);
-    //    let mut handle = unsafe { Self::new(data, info, contexts) };
-    //    handle.plugin = entry.entry as *mut RawPh;
-    //    handle.set_context(&self.get_context());
-    //    f(&mut handle)
-    //}
+    /// Operates on a virtual plugin.
+    ///
+    /// # Examples
+    ///
+    /// ```no_run
+    /// use hexchat_unsafe_plugin::{PluginHandle};
+    ///
+    /// fn contexts_can_be_passed_around(ph: &mut PluginHandle<'_>) {
+    ///     let ctx = ph.get_context();
+    ///     let mut vplug = ph.plugingui_add("foo", "bar", "baz", "qux");
+    ///     ph.for_entry_mut(&mut vplug, |ph| {
+    ///         ph.set_context(&ctx);
+    ///         ph.get_context()
+    ///     });
+    /// }
+    /// ```
+    pub fn for_entry_mut<F, R>(&mut self, entry: &mut PluginEntryHandle<'ph>, f: F) -> R where F: FnOnce(&mut PluginHandle<'ph>) -> R {
+        // we're doing something kinda (very) weird here, but this is the only
+        // way to get and set pluginprefs for virtual plugins. (not that we
+        // support those yet...)
+        // this should be sound?
+        let data = self.data;
+        let info = self.info;
+        let contexts = Rc::clone(&self.contexts);
+        let mut handle = unsafe { Self::new(data, info, contexts) };
+        handle.plugin = entry.entry as *mut RawPh;
+        handle.set_context(&self.get_context());
+        f(&mut handle)
+    }
 
     /// Registers a virtual plugin.
     pub fn plugingui_add(&self, filename: &str, name: &str, description: &str, version: &str) -> PluginEntryHandle<'ph> {