diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 56 |
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> { |