Attribute Macro extism_pdk::plugin_fn

source ·
#[plugin_fn]
Expand description

plugin_fn is used to define an Extism callable function to export

It should be added to a function you would like to export, the function should accept a parameter that implements extism_pdk::FromBytes and return a extism_pdk::FnResult that contains a value that implements extism_pdk::ToBytes. This maps input and output parameters to Extism input and output instead of using function arguments directly.

§Example

use extism_pdk::{FnResult, plugin_fn};
#[plugin_fn]
pub fn greet(name: String) -> FnResult<String> {
  let s = format!("Hello, {name}");
  Ok(s)
}