Skip to main content

export_plugin

Macro export_plugin 

Source
macro_rules! export_plugin {
    ($plugin:ty) => { ... };
}
Expand description

Macro to export all required plugin functions

This macro generates the plugin_manifest, plugin_execute, plugin_resume, plugin_alloc, and plugin_dealloc functions required by the host.

§Example

struct MyPlugin;

impl Plugin for MyPlugin {
    fn manifest() -> PluginManifest { /* ... */ }
    fn execute(args: Vec<String>) -> ExecuteResult { /* ... */ }
}

export_plugin!(MyPlugin);

§Effects (Optional)

For plugins that use effects (HTTP, sleep, etc.), implement resume:

impl Plugin for MyPlugin {
    // ...
    fn resume(effect_id: u32, result: EffectResult) -> ExecuteResult {
        match result {
            EffectResult::Http(resp) => ExecuteResult::success(resp.body),
            EffectResult::Error(e) => ExecuteResult::user_error(e),
            _ => ExecuteResult::system_error("Unexpected result"),
        }
    }
}