Attribute Macro plugin

#[plugin]
Expand description

Registers a native Kanzi plugin.

§Attributes

  • plugin(name = PLUGIN_NAME) - Specifies the name used to import the plugin into Kanzi Studio project. The name must be specified if the plugin is linked statically.

§Requirements

A struct implementing a plugin interface must have a default constructor through Default trait.

§Usage

#[kanzi::plugin]
#[derive(Default)]
struct XmlDataSourcePlugin {}

impl kanzi::IPlugin for XmlDataSourcePlugin {
    fn register_metadata_override(&self, domain: &kanzi::Domain) -> kanzi::Result<()> {
        data_source::XmlDataSource::register(domain)
    }
}

Created plugin can be linked statically, by manually calling register_metadata_override on its struct:

fn with_kanzi(domain: &kanzi::Domain) -> kanzi::Result<()> {
    use kanzi::IPlugin;
    XmlDataSourcePlugin::default().register_metadata_override(domain)?;
    Ok(())
}

Created plugin can be linked dynamically. For that the crate where a plugin is defined needs to have crate-type specified in Cargo.toml:

[lib]
crate-type = ["cdylib"]

This macro will generate an extern "C" function expected by Kanzi Studio, which will let Kanzi Studio load compiled plugin.