use wasmtime::*;
fn main() -> Result<()> {
let wasm_bytes = std::fs::read("/Users/dangoodman/code/learningRust/wasm/code/pkg/code_bg.wasm")?;
let engine = Engine::default();
let mut store = Store::new(&engine, ());
let uppercase = instance.get_func(&mut store, "uppercase").unwrap();
let upper_typed = uppercase.typed::<(&str,), (String,)>(&store)?;
Which gives me the following error:
Compiling host v0.1.0 (/Users/dangoodman/code/learningRust/wasm/host)
error[E0277]: the trait bound `(&str,): WasmParams` is not satisfied
--> src/main.rs:27:41
|
27 | let upper_typed = uppercase.typed::<(&str,), (String,)>(&store)?;
| ----- ^^^^^^^ the trait `WasmParams` is not implemented for `(&str,)`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `WasmParams`:
()
(A1, A2)
(A1, A2, A3)
(A1, A2, A3, A4)
(A1, A2, A3, A4, A5)
(A1, A2, A3, A4, A5, A6)
(A1, A2, A3, A4, A5, A6, A7)
(A1, A2, A3, A4, A5, A6, A7, A8)
and 10 others
note: required by a bound in `wasmtime::Func::typed`
--> /Users/dangoodman/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-26.0.1/src/runtime/func.rs:1563:17
|
1558 | pub fn typed<Params, Results>(
| ----- required by a bound in this associated function
...
1563 | Params: WasmParams,
| ^^^^^^^^^^ required by this bound in `Func::typed`
error[E0277]: the trait bound `(std::string::String,): WasmResults` is not satisfied
--> src/main.rs:27:50
|
27 | let upper_typed = uppercase.typed::<(&str,), (String,)>(&store)?;
| ----- ^^^^^^^^^ the trait `WasmResults` is not implemented for `(std::string::String,)`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `WasmResults`:
()
(A1, A2)
(A1, A2, A3)
(A1, A2, A3, A4)
(A1, A2, A3, A4, A5)
(A1, A2, A3, A4, A5, A6)
(A1, A2, A3, A4, A5, A6, A7)
(A1, A2, A3, A4, A5, A6, A7, A8)
and 10 others
note: required by a bound in `wasmtime::Func::typed`
--> /Users/dangoodman/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-26.0.1/src/runtime/func.rs:1564:18
|
1558 | pub fn typed<Params, Results>(
| ----- required by a bound in this associated function
...
1564 | Results: WasmResults,
| ^^^^^^^^^^^ required by this bound in `Func::typed`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `host` (bin "host") due to 2 previous errors
Is the example wrong, or am I using the crate incorrectly?
The docs state:
Types specified here must implement the ComponentType trait. This trait is implemented for built-in types to Rust such as integer primitives, floats, Option, Result<T, E>, strings, Vec, and more. As parameters you’ll be passing native Rust types.
At https://docs.rs/wasmtime/26.0.1/wasmtime/component/struct.Func.html the following example is shown:
I have recreated this setup via:
lib.rs
Compiled with
wasm-pack build --target web
main.rs
(another crate)Which gives me the following error:
Is the example wrong, or am I using the crate incorrectly?
The docs state:
And the trait for these types seem to be implemented according to https://docs.rs/wasmtime/26.0.1/wasmtime/component/trait.ComponentType.html
It's being imported as
wasmtime = { version = "26.0.1", features = ["component-model", "runtime"] }
Edit: it also seems to have a similar issue for calling the function: