Trait hexchat_unsafe_plugin::Plugin
source · [−]pub unsafe trait Plugin<'ph> {
fn init(
self: Pin<&mut Self>,
ph: &mut PluginHandle<'ph>,
filename: &str,
arg: Option<&str>
) -> bool;
fn deinit(self: Pin<&mut Self>, ph: &mut PluginHandle<'ph>) { ... }
}
Expand description
A hexchat plugin.
Safety
Modern operating systems cannot deal with dynamic unloading when threads are involved, because we still haven’t figured out how to track which code address started a syscall that spawned a thread for some reason, so there’s no way for the dynamic loader to stop those threads when unloading.
Fortunately we can just shift that responsibility onto the unsuspecting Rust user. Because Rust is a safe language, this makes writing plugins inherently unsafe!
At least Unsafe Rust is still safer than writing C. So you have that going.
TL;DR: Either don’t use threads, or ensure they’re dead in Drop
/deinit
.
Required Methods
Provided Methods
fn deinit(self: Pin<&mut Self>, ph: &mut PluginHandle<'ph>)
fn deinit(self: Pin<&mut Self>, ph: &mut PluginHandle<'ph>)
Called to deinitialize the plugin.
This is always called immediately prior to Drop::drop.
A note about unwinding
Panics in deinit will prevent the plugin from being correctly unloaded! Be careful!