Add more complexity to example with custom record and parameters

This commit is contained in:
2025-01-09 16:34:26 +10:30
parent fca84b9240
commit 90dc149f6a
7 changed files with 29 additions and 20 deletions

View File

@@ -12,8 +12,8 @@ struct TestState {
}
impl TestImports for TestState {
fn hello(&mut self) -> std::result::Result<(), wasmtime::Error> {
println!("{}", self.name);
fn hello(&mut self, hello_string: RecordString) -> std::result::Result<(), wasmtime::Error> {
println!("{} - {}", self.name, hello_string.hello_string);
Ok(())
}
}
@@ -22,7 +22,7 @@ fn main() -> wasmtime::Result<()> {
let mut config = Config::new();
config.wasm_component_model(true);
let engine = Engine::new(&config)?;
let component = Component::from_file(&engine, "target/wasm32-wasi/release/component.wasm")?;
let component = Component::from_file(&engine, "target/wasm32-wasip1/release/component.wasm")?;
let mut linker = Linker::new(&engine);
Test::add_to_linker(&mut linker, |state: &mut TestState| state)?;
let mut store = Store::new(
@@ -32,6 +32,6 @@ fn main() -> wasmtime::Result<()> {
},
);
let (bindings, _) = Test::instantiate(&mut store, &component, &linker)?;
bindings.call_greet(&mut store)?;
bindings.call_greet(&mut store, &RecordString { hello_string: "Hello".to_owned() })?;
Ok(())
}