[][src]Function message_plugins::construct_plugin_with_constructor

pub fn construct_plugin_with_constructor<T>(
    path: impl AsRef<OsStr>,
    constructor: impl AsRef<[u8]>,
    args: Option<&dyn Any>
) -> Result<Box<dyn Plugin<T>>, PluginConstructionError>

Loads a dynamic library at path, and calls the function called constructor in order to instanciate a Plugin. The constructor function is the only function where you need to dirty your hands with extern "C". Its sole purpose is to insert your boxed plugin into a pointer. I suggest writing a constructor of the style:

#[no_mangle]
unsafe extern "C" fn plugin_constructor(ptr: *mut Box<dyn Plugin<YourMessageType>>) {
    let plugin = Box::new(YourPlugin::new());
    insert_instace(ptr, plugin);
}