Simplify examples: avoid unnecessary HostRef wrap/unwrap

Several of the examples wrap the Instance in a HostRef, only to
immediately borrow it again to get the exports,and then never touch it
again. Simplify this by owning the Instance directly.
This commit is contained in:
Josh Triplett
2019-11-19 21:01:09 -08:00
committed by Jakub Konka
parent 204b4d376a
commit 7c8ac3d71c
4 changed files with 10 additions and 21 deletions

View File

@@ -55,13 +55,10 @@ fn main() -> Result<()> {
.0;
// Instantiate the module.
let instance = HostRef::new(Instance::new(&store, &module, &[])?);
let instance = Instance::new(&store, &module, &[])?;
// Invoke `gcd` export
let gcd = instance.borrow().exports()[gcd_index]
.func()
.expect("gcd")
.clone();
let gcd = instance.exports()[gcd_index].func().expect("gcd").clone();
let result = gcd
.borrow()
.call(&[Val::from(6i32), Val::from(27i32)])