Skip to main content

zlayer_plugin

Macro zlayer_plugin 

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

Register a plugin implementation with the ZLayer runtime.

This macro generates the necessary WIT binding exports for your plugin type. Your type must implement the ZLayerPlugin trait and Default.

§Example

use zlayer_sdk::prelude::*;
use zlayer_sdk::{ZLayerPlugin, zlayer_plugin};

struct MyPlugin;
impl Default for MyPlugin {
    fn default() -> Self { Self }
}

impl ZLayerPlugin for MyPlugin {
    fn info(&self) -> PluginInfo {
        PluginInfo {
            id: "example:my-plugin".into(),
            name: "My Plugin".into(),
            version: Version { major: 1, minor: 0, patch: 0, pre_release: None },
            description: "Example plugin".into(),
            author: "Example".into(),
            license: None,
            homepage: None,
            metadata: vec![],
        }
    }

    fn handle(&self, event_type: &str, payload: &[u8]) -> Result<Vec<u8>, String> {
        Ok(payload.to_vec())
    }
}

zlayer_plugin!(MyPlugin);