use extism::Plugin;
use std::path::Path;
pub struct WasmDispatcher;
impl WasmDispatcher {
pub fn execute_plugin(
plugin_path: &str,
function_name: &str,
input_data: &str,
) -> Result<String, String> {
let wasm_file_path = Path::new(plugin_path);
if !wasm_file_path.exists() {
return Err(format!("Plugin file not found at path: {}", plugin_path));
}
let wasm_bytes = std::fs::read(wasm_file_path)
.map_err(|e| format!("Failed to read WASM bytes from file: {}", e))?;
let mut plugin = Plugin::new(&wasm_bytes, [], true)
.map_err(|e| format!("Failed to initialize Extism plugin: {}", e))?;
let output = plugin
.call::<&str, &str>(function_name, input_data)
.map_err(|e| format!("Extism guest execution failed: {}", e))?;
Ok(output.to_string())
}
}