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

Method validate_init_func

crates/wizer/src/wasmtime.rs:31–52  ·  view source on GitHub ↗

Check that the module exports an initialization function, and that the function has the correct type.

(&self, module: &wasmtime::Module)

Source from the content-addressed store, hash-verified

29 /// Check that the module exports an initialization function, and that the
30 /// function has the correct type.
31 fn validate_init_func(&self, module: &wasmtime::Module) -> wasmtime::Result<()> {
32 log::debug!("Validating the exported initialization function");
33 match module.get_export(self.get_init_func()) {
34 Some(wasmtime::ExternType::Func(func_ty)) => {
35 if func_ty.params().len() != 0 || func_ty.results().len() != 0 {
36 wasmtime::bail!(
37 "the Wasm module's `{}` function export does not have type `[] -> []`",
38 self.get_init_func()
39 );
40 }
41 }
42 Some(_) => wasmtime::bail!(
43 "the Wasm module's `{}` export is not a function",
44 self.get_init_func()
45 ),
46 None => wasmtime::bail!(
47 "the Wasm module does not have a `{}` export",
48 self.get_init_func()
49 ),
50 }
51 Ok(())
52 }
53
54 /// Instantiate the module and call its initialization function.
55 async fn initialize<T: Send>(

Callers 1

runMethod · 0.80

Calls 6

OkFunction · 0.85
get_init_funcMethod · 0.80
get_exportMethod · 0.45
lenMethod · 0.45
paramsMethod · 0.45
resultsMethod · 0.45

Tested by

no test coverage detected