-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
more-typesAdding support for more Rust types to cross the boundaryAdding support for more Rust types to cross the boundary
Description
It would really be great to be able to return a vector of structs or tuples:
For example. I have the following type:
#[wasm_bindgen]
struct Range {
offset: u32,
length: u32
}
that I want to return in my function
#[wasm_bindgen]
pub fn token_ranges(text: &str) -> Vec<Range>
I am getting this error:
Compiling picl_wasm_runtime v0.1.0 (file:///A:/Repos/picl_native_runtime/bindings/typescript)
error[E0277]: the trait bound `std::boxed::Box<[Range]>: wasm_bindgen::convert::WasmBoundary` is not satisfied
--> src\lib.rs:15:1
|
15 | #[wasm_bindgen]
| ^^^^^^^^^^^^^^^ the trait `wasm_bindgen::convert::WasmBoundary` is not implemented for `std::boxed::Box<[Range]>`
|
= help: the following implementations were found:
<std::boxed::Box<[u16]> as wasm_bindgen::convert::WasmBoundary>
<std::boxed::Box<[i16]> as wasm_bindgen::convert::WasmBoundary>
<std::boxed::Box<[f32]> as wasm_bindgen::convert::WasmBoundary>
<std::boxed::Box<[i32]> as wasm_bindgen::convert::WasmBoundary>
and 5 others
= note: required because of the requirements on the impl of `wasm_bindgen::convert::WasmBoundary` for `std::vec::Vec<Range>`
My workaround is to flatten my data and return a Vec and then splice my token ranges on the JS side. This is unfortunate...
How can I add a WasmBoundary trait for a custom type?
Is there a better way?
David-OConnor, varkor, IOuser, phayes, bokuweb and 123 morekatopz, usagi and alfinsyahruddin
Metadata
Metadata
Assignees
Labels
more-typesAdding support for more Rust types to cross the boundaryAdding support for more Rust types to cross the boundary