[wasmtime-api] reduce examples complexity: hostref for store/engine (#489)

* reduce amount of store.clone()

* use HostRef Engine as ref / use Engine::default()
This commit is contained in:
Yury Delendik
2019-11-07 11:39:23 -06:00
committed by GitHub
parent 55eb06ecc2
commit 6632a7da37
13 changed files with 76 additions and 88 deletions

View File

@@ -10,10 +10,10 @@ fn main() -> Result<()> {
// Instantiate engine and store.
let engine = HostRef::new(Engine::default());
let store = HostRef::new(Store::new(engine));
let store = HostRef::new(Store::new(&engine));
// Load a module.
let module = HostRef::new(Module::new(store.clone(), &wasm)?);
let module = HostRef::new(Module::new(&store, &wasm)?);
// Find index of the `gcd` export.
let gcd_index = module
@@ -26,7 +26,7 @@ fn main() -> Result<()> {
.0;
// Instantiate the module.
let instance = HostRef::new(Instance::new(store.clone(), module, &[])?);
let instance = HostRef::new(Instance::new(&store, &module, &[])?);
// Invoke `gcd` export
let gcd = instance.borrow().exports()[gcd_index]