Macro static_plugin

Source
macro_rules! static_plugin {
    ($(#[$attr:tt])? $name:ident = $ty:ty) => { ... };
    ($name:ident @ unsafe { $maj:expr; $min:expr; $patch:expr } = #[no_capabilities] $ty:ty) => { ... };
    ($name:ident @ unsafe { $maj:expr; $min:expr; $patch:expr } = $ty:ty) => { ... };
}
Expand description

§Automatically generate the Falco plugin API structure for static plugins

This macro generates a falco_plugin_api::plugin_api structure, usable as a statically linked plugin. It automatically handles all supported capabilities, so you need just one invocation, regardless of how many capabilities your plugin supports.

§Basic usage

use falco_plugin::base::Plugin;
use falco_plugin::static_plugin;

impl Plugin for MyPlugin {
    // ...
}

static_plugin!(#[no_capabilities] MY_PLUGIN_API = MyPlugin);

This expands to:

#[no_mangle]
static MY_PLUGIN_API: falco_plugin::api::plugin_api = /* ... */;

The symbols referred to in the API structure are still mangled according to default Rust rules.

§Overriding the supported API version

The macro also implements a form where you can override the required API version (for example, if you wish to advertise an older version for increased compatibility):

use falco_plugin::base::Plugin;
use falco_plugin::static_plugin;

impl Plugin for MyPlugin {
    // ...
}

// advertise API version 3.3.0
static_plugin!(MY_PLUGIN_API @ unsafe { 3;3;0 } = #[no_capabilities] MyPlugin);

Note: this does not affect the actual version supported in any way. If you use this form, it’s entirely your responsibility to ensure the advertised version is compatible with the actual version supported by this crate.