rust - 返回 Box<[Box<[JsValue]>]> 不起作用,因为 IntoWasmAbi 未实现
问题描述
我正在尝试在JsValue
数组上创建一个块方法。有没有办法将修改后的数组传回 JavaScript?
这就是我想要做的:
#[wasm_bindgen]
pub fn chunk(array: Box<[JsValue]>, size: usize) -> Box<[Box<[JsValue]>]> {
array
.chunks(size)
.map(|el| {
el.iter()
.map(|el| el.to_owned())
.collect::<Box<[JsValue]>>()
})
.collect()
}
我在编译过程中得到了这个:
the trait `wasm_bindgen::convert::traits::IntoWasmAbi` is not
implemented for
`std::boxed::Box<[std::boxed::Box<[wasm_bindgen::JsValue]>]>`
我也尝试过 js_sys,但它似乎比纯 JS 实现需要更长的时间,因为它只是一个 JS API 包装器
#[wasm_bindgen]
pub fn chunk(array: Box<[JsValue]>, size: usize) -> Array {
let root = Array::new();
for chunk in array.chunks(size) {
let arr = Array::new();
for ch in chunk {
arr.push(ch);
}
root.push(&arr);
}
root
}
解决方案
推荐阅读
- fonts - 渲染字体字符 LSB 或位置不同
- reactjs - 使用 jwt 登录表单并做出反应
- r - 如何从 ggplot2 中 x 轴的 %m 中删除前导零
- marklogic - MarkLogic 中过滤搜索结果的深度分页
- node.js - 通过别名而不是 IP 地址访问 LAN 服务器上的 Node.js 应用程序
- react-native - 从 Axios 获取基本 URL - 反应原生
- elasticsearch - 来自另一个查询的弹性 DSL 查询结果
- python-imaging-library - 在 python 3.7 Mac OS 中使用 Pillow?
- angular - 在角材料表的每一行中添加图标作为按钮
- javascript - 返回 Axios 数据,以便我可以使用它