danthegoodman1 opened issue #9589:
At https://docs.rs/wasmtime/26.0.1/wasmtime/component/struct.Func.html the following example is shown:
Calling a function which takes one string parameter and returns a string:
rs let typed = func.typed::<(&str,), (String,)>(&store)?; let ret = typed.call(&mut store, ("Hello, ",))?.0; println!("returned string was: {}", ret);
I have recreated this setup via:
use wasm_bindgen::prelude::*; #[wasm_bindgen] pub fn uppercase(input: &str) -> String { input.to_uppercase() }
Compiled with
wasm-pack build --target web
main.rs (another directory)
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<T>, Result<T, E>, strings, Vec<T>, and more. As parameters you’ll be passing native Rust types.
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"] }
danthegoodman1 edited issue #9589:
At https://docs.rs/wasmtime/26.0.1/wasmtime/component/struct.Func.html the following example is shown:
Calling a function which takes one string parameter and returns a string:
rs let typed = func.typed::<(&str,), (String,)>(&store)?; let ret = typed.call(&mut store, ("Hello, ",))?.0; println!("returned string was: {}", ret);
I have recreated this setup via:
use wasm_bindgen::prelude::*; #[wasm_bindgen] pub fn uppercase(input: &str) -> String { input.to_uppercase() }
Compiled with
wasm-pack build --target web
main.rs (another directory)
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<T>, Result<T, E>, strings, Vec<T>, and more. As parameters you’ll be passing native Rust types.
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:
<img width="1168" alt="image" src="https://github.com/user-attachments/assets/062b378c-e8d9-4999-8a12-c195088b5b8f">
danthegoodman1 edited issue #9589:
At https://docs.rs/wasmtime/26.0.1/wasmtime/component/struct.Func.html the following example is shown:
Calling a function which takes one string parameter and returns a string:
rs let typed = func.typed::<(&str,), (String,)>(&store)?; let ret = typed.call(&mut store, ("Hello, ",))?.0; println!("returned string was: {}", ret);
I have recreated this setup via:
lib.rs
use wasm_bindgen::prelude::*; #[wasm_bindgen] pub fn uppercase(input: &str) -> String { input.to_uppercase() }
Compiled with
wasm-pack build --target web
main.rs
(another directory)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<T>, Result<T, E>, strings, Vec<T>, and more. As parameters you’ll be passing native Rust types.
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:
<img width="1168" alt="image" src="https://github.com/user-attachments/assets/062b378c-e8d9-4999-8a12-c195088b5b8f">
danthegoodman1 edited issue #9589:
At https://docs.rs/wasmtime/26.0.1/wasmtime/component/struct.Func.html the following example is shown:
Calling a function which takes one string parameter and returns a string:
rs let typed = func.typed::<(&str,), (String,)>(&store)?; let ret = typed.call(&mut store, ("Hello, ",))?.0; println!("returned string was: {}", ret);
I have recreated this setup via:
lib.rs
use wasm_bindgen::prelude::*; #[wasm_bindgen] pub fn uppercase(input: &str) -> String { input.to_uppercase() }
Compiled with
wasm-pack build --target web
main.rs
(another crate)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<T>, Result<T, E>, strings, Vec<T>, and more. As parameters you’ll be passing native Rust types.
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:
<img width="1168" alt="image" src="https://github.com/user-attachments/assets/062b378c-e8d9-4999-8a12-c195088b5b8f">
danthegoodman1 closed issue #9589:
At https://docs.rs/wasmtime/26.0.1/wasmtime/component/struct.Func.html the following example is shown:
Calling a function which takes one string parameter and returns a string:
rs let typed = func.typed::<(&str,), (String,)>(&store)?; let ret = typed.call(&mut store, ("Hello, ",))?.0; println!("returned string was: {}", ret);
I have recreated this setup via:
lib.rs
use wasm_bindgen::prelude::*; #[wasm_bindgen] pub fn uppercase(input: &str) -> String { input.to_uppercase() }
Compiled with
wasm-pack build --target web
main.rs
(another crate)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<T>, Result<T, E>, strings, Vec<T>, and more. As parameters you’ll be passing native Rust types.
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:
<img width="1168" alt="image" src="https://github.com/user-attachments/assets/062b378c-e8d9-4999-8a12-c195088b5b8f">
danthegoodman1 commented on issue #9589:
Seems I didn't use the component model for this. Wish there was a guide on that!
Last updated: Nov 22 2024 at 17:03 UTC