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

Function main

examples/resource-component/main.rs:123–144  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

121
122#[tokio::main]
123async fn main() -> Result<()> {
124 let engine = Engine::default();
125 let mut linker = Linker::new(&engine);
126 let state = ComponentRunStates::new();
127 let mut store = Store::new(&engine, state);
128
129 KvDatabase::add_to_linker::<_, HasSelf<_>>(&mut linker, |s| s)?;
130 add_to_linker_async(&mut linker)?;
131
132 // Instantiate our component with the imports we've created, and run its function
133 let component = Component::from_file(&engine, "target/wasm32-wasip2/debug/guest_kvdb.wasm")?;
134 let bindings = KvDatabase::instantiate_async(&mut store, &component, &linker).await?;
135 let result = bindings
136 .call_replace_value(&mut store, "hello", "world")
137 .await?;
138 assert_eq!(result, None);
139 let result = bindings
140 .call_replace_value(&mut store, "hello", "wasmtime")
141 .await?;
142 assert_eq!(result, Some("world".to_string()));
143 Ok(())
144}

Callers

nothing calls this directly

Calls 4

instantiate_asyncFunction · 0.85
OkFunction · 0.85
newFunction · 0.50
add_to_linker_asyncFunction · 0.50

Tested by

no test coverage detected