From 26f9ce02bce3c5e124e4427ef65efd1c17a8b8f4 Mon Sep 17 00:00:00 2001 From: matt rice Date: Fri, 14 Apr 2023 15:32:05 +0000 Subject: [PATCH] For clarity in examples avoid importing/exporting functions of the same name. (#6211) --- crates/wasmtime/README.md | 4 ++-- crates/wasmtime/src/lib.rs | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/wasmtime/README.md b/crates/wasmtime/README.md index 7c2cddd490fa..a1b29d7fe344 100644 --- a/crates/wasmtime/README.md +++ b/crates/wasmtime/README.md @@ -72,7 +72,7 @@ fn main() -> Result<()> { let engine = Engine::default(); let wat = r#" (module - (import "host" "hello" (func $host_hello (param i32))) + (import "host" "host_func" (func $host_hello (param i32))) (func (export "hello") i32.const 3 @@ -84,7 +84,7 @@ fn main() -> Result<()> { // Create a `Linker` which will be later used to instantiate this module. // Host functionality is defined by name within the `Linker`. let mut linker = Linker::new(&engine); - linker.func_wrap("host", "hello", |caller: Caller<'_, u32>, param: i32| { + linker.func_wrap("host", "host_func", |caller: Caller<'_, u32>, param: i32| { println!("Got {} from WebAssembly", param); println!("my host state is: {}", caller.data()); })?; diff --git a/crates/wasmtime/src/lib.rs b/crates/wasmtime/src/lib.rs index dd54cdc77e9f..b1ba2004be3e 100644 --- a/crates/wasmtime/src/lib.rs +++ b/crates/wasmtime/src/lib.rs @@ -34,7 +34,7 @@ //! let engine = Engine::default(); //! let wat = r#" //! (module -//! (import "host" "hello" (func $host_hello (param i32))) +//! (import "host" "host_func" (func $host_hello (param i32))) //! //! (func (export "hello") //! i32.const 3 @@ -47,7 +47,7 @@ //! // `Store` has a type parameter to store host-specific data, which in //! // this case we're using `4` for. //! let mut store = Store::new(&engine, 4); -//! let host_hello = Func::wrap(&mut store, |caller: Caller<'_, u32>, param: i32| { +//! let host_func = Func::wrap(&mut store, |caller: Caller<'_, u32>, param: i32| { //! println!("Got {} from WebAssembly", param); //! println!("my host state is: {}", caller.data()); //! }); @@ -55,7 +55,7 @@ //! // Instantiation of a module requires specifying its imports and then //! // afterwards we can fetch exports by name, as well as asserting the //! // type signature of the function with `get_typed_func`. -//! let instance = Instance::new(&mut store, &module, &[host_hello.into()])?; +//! let instance = Instance::new(&mut store, &module, &[host_func.into()])?; //! let hello = instance.get_typed_func::<(), ()>(&mut store, "hello")?; //! //! // And finally we can call the wasm! @@ -146,7 +146,7 @@ //! let engine = Engine::default(); //! let wat = r#" //! (module -//! (import "host" "hello" (func $host_hello (param i32))) +//! (import "host" "host_func" (func $host_hello (param i32))) //! //! (func (export "hello") //! i32.const 3 @@ -157,7 +157,7 @@ //! //! // Create a `Linker` and define our host function in it: //! let mut linker = Linker::new(&engine); -//! linker.func_wrap("host", "hello", |caller: Caller<'_, u32>, param: i32| { +//! linker.func_wrap("host", "host_func", |caller: Caller<'_, u32>, param: i32| { //! println!("Got {} from WebAssembly", param); //! println!("my host state is: {}", caller.data()); //! })?;