macro_rules! typed_plugin {
($pub:vis $name:ident {$($f:ident $(< $( $lt:tt $( : $clt:path )? ),+ >)? ($input:ty) -> $output:ty);*$(;)?}) => { ... };
}Expand description
The typed_plugin macro is used to create a newtype wrapper around Plugin with methods defined for the specified functions.
For example, we can define a new type MyPlugin that automatically implements From/Into for Plugin
#[derive(serde::Deserialize)]
struct Count {
count: usize,
}
extism::typed_plugin!(MyPlugin {
count_vowels(&str) -> extism::convert::Json<Count>;
});
// Convert from `Plugin` to `MyPlugin`
let mut plugin: MyPlugin = extism::Plugin::new(WASM, [], true).unwrap().try_into().unwrap();
// and call the `count_vowels` function
let count = plugin.count_vowels("this is a test").unwrap();