[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

@@ -25,10 +25,10 @@ fn test_import_calling_export() {
}
let engine = HostRef::new(Engine::new(Config::default()));
let store = HostRef::new(Store::new(engine));
let store = HostRef::new(Store::new(&engine));
let module = HostRef::new(
Module::new(
store.clone(),
&store,
&read("tests/import_calling_export.wasm").expect("failed to read wasm file"),
)
.expect("failed to create module"),
@@ -39,15 +39,14 @@ fn test_import_calling_export() {
});
let callback_func = HostRef::new(Func::new(
store.clone(),
&store,
FuncType::new(Box::new([]), Box::new([])),
callback.clone(),
));
let imports = vec![callback_func.into()];
let instance = HostRef::new(
Instance::new(store.clone(), module, imports.as_slice())
.expect("failed to instantiate module"),
Instance::new(&store, &module, imports.as_slice()).expect("failed to instantiate module"),
);
let exports = Ref::map(instance.borrow(), |instance| instance.exports());