Skip to main content

export_plugin

Macro export_plugin 

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

Register a plugin for link-time collection.

The argument is an expression that makes the plugin, evaluated each time a host asks for it. It must not capture anything:

use rich_plugin_api::{Plugin, PluginError, PluginMetadata, PluginRegistrar};

struct Hello;
impl Plugin for Hello {
    fn metadata(&self) -> PluginMetadata {
        PluginMetadata::new("hello", "Hello", "1.0.0")
    }
    fn register(&self, _: &mut dyn PluginRegistrar) -> Result<(), PluginError> {
        Ok(())
    }
}

rich_plugin_api::export_plugin!(Hello);

assert!(rich_plugin_api::linked_plugins().any(|p| p.plugin().metadata().id == "hello"));