MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / load_plugin

Function load_plugin

examples/wasip2-plugins/src/main.rs:68–94  ·  view source on GitHub ↗
(
    state: &mut CalculatorState,
    engine: &Engine,
    linker: &Linker<()>,
    path: PathBuf,
)

Source from the content-addressed store, hash-verified

66}
67
68fn load_plugin(
69 state: &mut CalculatorState,
70 engine: &Engine,
71 linker: &Linker<()>,
72 path: PathBuf,
73) -> wasmtime::Result<()> {
74 println!("Loading plugin from file {:?}", path);
75
76 // Creates a component from a .wasm file
77 let component = Component::from_file(engine, &path)?;
78
79 let (plugin_name, plugin, store) = {
80 // Creates a Store for each plugin.
81 // A Store represents dynamic state, so each plugin
82 // has its own Store.
83 let mut store = Store::new(engine, ());
84 // Instantiate the plugin to the store we just created.
85 let plugin = Plugin::instantiate(&mut store, &component, linker)?;
86 (plugin.call_get_plugin_name(&mut store)?, plugin, store)
87 };
88
89 state
90 .plugin_descs
91 .insert(plugin_name, PluginDesc { plugin, store });
92
93 Ok(())
94}
95
96fn load_plugins(state: &mut CalculatorState, plugins_dir: &Path) -> wasmtime::Result<()> {
97 let engine = Engine::default();

Callers 1

load_pluginsFunction · 0.85

Calls 4

OkFunction · 0.85
newFunction · 0.50
instantiateFunction · 0.50
insertMethod · 0.45

Tested by

no test coverage detected