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:
committed by
Jakub Konka
parent
204b4d376a
commit
7c8ac3d71c
@@ -1,7 +1,6 @@
|
||||
//! Translation of multi example
|
||||
|
||||
use anyhow::{ensure, format_err, Context as _, Result};
|
||||
use std::cell::Ref;
|
||||
use std::rc::Rc;
|
||||
use wasmtime::*;
|
||||
|
||||
@@ -68,14 +67,12 @@ fn main() -> Result<()> {
|
||||
// Instantiate.
|
||||
println!("Instantiating module...");
|
||||
let imports = vec![callback_func.into()];
|
||||
let instance = HostRef::new(
|
||||
Instance::new(&store, &module, imports.as_slice())
|
||||
.context("Error instantiating module!")?,
|
||||
);
|
||||
let instance = Instance::new(&store, &module, imports.as_slice())
|
||||
.context("Error instantiating module!")?;
|
||||
|
||||
// Extract exports.
|
||||
println!("Extracting export...");
|
||||
let exports = Ref::map(instance.borrow(), |instance| instance.exports());
|
||||
let exports = instance.exports();
|
||||
ensure!(!exports.is_empty(), "Error accessing exports!");
|
||||
let g = exports[0].func().context("> Error accessing export $g!")?;
|
||||
let round_trip_many = exports[1]
|
||||
|
||||
Reference in New Issue
Block a user