mirror of
https://github.com/extism/extism.git
synced 2026-01-14 08:18:03 -05:00
Add an example of dynamically linking plugins and a benchmark that does an apples-to-apples comparison of `reflect` using host functions vs. `reflect` using a linked wasm module. (To my surprise, the host functions are a _little bit faster_!)
31 lines
869 B
Rust
31 lines
869 B
Rust
use extism::*;
|
|
|
|
fn main() {
|
|
let manifest = Manifest::new([
|
|
Wasm::File {
|
|
// See https://github.com/extism/plugins/blob/main/upper.wat
|
|
path: "../wasm/upper.wasm".into(),
|
|
meta: WasmMetadata {
|
|
name: Some("extism:host/user".to_string()),
|
|
hash: None,
|
|
},
|
|
},
|
|
Wasm::File {
|
|
// See https://github.com/extism/plugins/tree/main/reflect
|
|
path: "../wasm/reflect.wasm".into(),
|
|
meta: WasmMetadata {
|
|
name: Some("main".to_string()),
|
|
hash: None,
|
|
},
|
|
},
|
|
]);
|
|
let mut plugin = PluginBuilder::new(manifest).build().unwrap();
|
|
|
|
for _ in 0..5 {
|
|
let res = plugin
|
|
.call::<&str, &str>("reflect", "Hello, world!")
|
|
.unwrap();
|
|
println!("{}", res);
|
|
}
|
|
}
|