mirror of
https://github.com/mii443/wasmer.git
synced 2025-09-02 07:29:21 +00:00
chore(examples): Minor edits to the exported functions example
This commit is contained in:
@ -72,10 +72,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
println!("Calling `sum` function...");
|
println!("Calling `sum` function...");
|
||||||
// Let's call the `sum` exported function. The parameters are a
|
// Let's call the `sum` exported function. The parameters are a
|
||||||
// slice of `Value`s. The results are a boxed slice of `Value`s.
|
// slice of `Value`s. The results are a boxed slice of `Value`s.
|
||||||
let results = sum.call(&[Value::I32(1), Value::I32(2)])?;
|
let args = [Value::I32(1), Value::I32(2)];
|
||||||
|
let result = sum.call(&args)?;
|
||||||
|
|
||||||
println!("Results: {:?}", results);
|
println!("Results: {:?}", result);
|
||||||
assert_eq!(results.to_vec(), vec![Value::I32(3)]);
|
assert_eq!(result.to_vec(), vec![Value::I32(3)]);
|
||||||
|
|
||||||
// That was fun. But what if we can get rid of the `Value`s? Well,
|
// That was fun. But what if we can get rid of the `Value`s? Well,
|
||||||
// that's possible with the `NativeFunction` API. The function
|
// that's possible with the `NativeFunction` API. The function
|
||||||
@ -91,10 +92,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// Let's call the `sum` exported function. The parameters are
|
// Let's call the `sum` exported function. The parameters are
|
||||||
// statically typed Rust values of type `i32` and `i32`. The
|
// statically typed Rust values of type `i32` and `i32`. The
|
||||||
// result, in this case particular case, in a unit of type `i32`.
|
// result, in this case particular case, in a unit of type `i32`.
|
||||||
let result = sum_native.call(1, 2)?;
|
let result = sum_native.call(3, 4)?;
|
||||||
|
|
||||||
println!("Results: {:?}", result);
|
println!("Results: {:?}", result);
|
||||||
assert_eq!(result, 3);
|
assert_eq!(result, 7);
|
||||||
|
|
||||||
// Much nicer, isn't it?
|
// Much nicer, isn't it?
|
||||||
//
|
//
|
||||||
|
Reference in New Issue
Block a user