mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-16 17:18:57 +00:00
Rename {native,typed} functions, reintroduce *_with_env variants
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
//!
|
||||
//! Ready?
|
||||
|
||||
use wasmer::{imports, wat2wasm, FunctionEnv, Instance, Module, Store, TypedFunction, Value};
|
||||
use wasmer::{imports, wat2wasm, Instance, Module, Store, TypedFunction, Value};
|
||||
use wasmer_compiler_cranelift::Cranelift;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
@@ -81,17 +81,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// that's possible with the `TypedFunction` API. The function
|
||||
// will use native Rust values.
|
||||
//
|
||||
// Note that `native` takes 2 generic parameters: `Args` and
|
||||
// Note that `typed` takes 2 generic parameters: `Args` and
|
||||
// `Rets`, respectively for the parameters and the results. If
|
||||
// those values don't match the exported function signature, an
|
||||
// error will be raised.
|
||||
let sum_native: TypedFunction<(i32, i32), i32> = sum.native(&mut store)?;
|
||||
let sum_typed: TypedFunction<(i32, i32), i32> = sum.typed(&mut store)?;
|
||||
|
||||
println!("Calling `sum` function (natively)...");
|
||||
// Let's call the `sum` exported function. The parameters are
|
||||
// statically typed Rust values of type `i32` and `i32`. The
|
||||
// result, in this case particular case, in a unit of type `i32`.
|
||||
let result = sum_native.call(&mut store, 3, 4)?;
|
||||
let result = sum_typed.call(&mut store, 3, 4)?;
|
||||
|
||||
println!("Results: {:?}", result);
|
||||
assert_eq!(result, 7);
|
||||
|
||||
Reference in New Issue
Block a user