如何从WASM_BINDGEN函数返回嵌套数组
我有一个Rust程序,我想在JavaScript中以Web组件的身份运行。我有一个要返回3D数组的函数,因此我可以在前端的图表上绘制一些数据,但是我找不到返回此类数据的方法。看看JS_SYS,没有一般数组类型,只有2D数组(例如UINT32Array)的特定类型。
我希望函数签名看起来像这样:
#[wasm_bindgen]
pub fn sk_dataset(input: &str) -> Vec<Vec<i32>>;
我尝试过使用WASM_BINDGEN DECONATOR返回结构:
#[wasm_bindgen]
pub struct DataSet {
pub data: Vec<Vec<i32>>
}
但是我遇到了一个错误,说明
the trait bound `Vec<i32>: JsObject` is not satisfied
required because of the requirements on the impl of `IntoWasmAbi` for `Box<[Vec<i32>]>`
教程
I have a rust program which I would like to run as web assembly in javascript. I have a function which I want to return a 3D array, so I can plot some data on a graph on the frontend, but I cannot find a way to return such data. Having a look at js_sys there is no general Array type, only specific types for 2D arrays such as Uint32Array.
I would like the function signature to look something like this:
#[wasm_bindgen]
pub fn sk_dataset(input: &str) -> Vec<Vec<i32>>;
I have tried return a struct with the wasm_bindgen decorator like this:
#[wasm_bindgen]
pub struct DataSet {
pub data: Vec<Vec<i32>>
}
But I get an error stating that
the trait bound `Vec<i32>: JsObject` is not satisfied
required because of the requirements on the impl of `IntoWasmAbi` for `Box<[Vec<i32>]>`
The tutorial over at https://rustwasm.github.io/docs/wasm-bindgen/reference/types/exported-rust-types.html only has examples of structs exported with basic types like i32s, how can I export a struct with more complex members?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论