plugin_impl

Attribute Macro plugin_impl 

Source
#[plugin_impl]
Expand description

A procedural macro for generating guest-side implementations of trait methods.

This macro takes an implementation block for a trait and generates corresponding guest-side functions for each method in the trait. The generated functions are meant to be used in an external C interface for interacting with the methods from a guest environment, such as WebAssembly.

The plugin_impl macro automates the process of generating unsafe external C functions that can be called from a guest environment to invoke methods on the trait implementation.

§Example

use plugy_macros::plugin_impl;

trait Plugin {
    fn greet(&self) -> String;
}

struct MyGreetPlugin;

#[plugin_impl]
impl Plugin for MyGreetPlugin {
    fn greet(&self) -> String {
        "Hello, from MyGreetPlugin!".to_string()
    }
}

In this example, the plugin_impl macro will generate bindings the greet method from the Plugin trait. The generated function can then be used to call the greet method from a host environment.