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

Function main

examples/component/main.rs:38–56  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

36}
37
38fn main() -> Result<()> {
39 // Create an engine with the component model enabled (disabled by default).
40 let engine = Engine::new(Config::new().wasm_component_model(true))?;
41
42 // NOTE: The wasm32-unknown-unknown target is used here for simplicity, real world use cases
43 // should probably use the wasm32-wasip1 target, and enable wasi preview2 within the component
44 // model.
45 let component = convert_to_component("target/wasm32-unknown-unknown/debug/guest.wasm")?;
46
47 // Create our component and call our generated host function.
48 let component = Component::from_binary(&engine, &component)?;
49 let mut store = Store::new(&engine, MyState {});
50 let mut linker = Linker::new(&engine);
51 host::add_to_linker::<_, HasSelf<_>>(&mut linker, |state| state)?;
52 let convert = Convert::instantiate(&mut store, &component, &linker)?;
53 let result = convert.call_convert_celsius_to_fahrenheit(&mut store, 23.4)?;
54 println!("Converted to: {result:?}");
55 Ok(())
56}

Callers

nothing calls this directly

Calls 5

convert_to_componentFunction · 0.85
OkFunction · 0.85
newFunction · 0.50
instantiateFunction · 0.50
wasm_component_modelMethod · 0.45

Tested by

no test coverage detected