小编buc*_*000的帖子

如何使用 Vec<T> 作为返回类型并使用 wasm_bindgen 使其在 Javascript 中可读

我想编译以下代码。

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub struct Dummy {}

#[wasm_bindgen]
pub fn test() -> Vec<Dummy> {
    vec![]
}
Run Code Online (Sandbox Code Playgroud)

但是,编译器不允许我这样做。

error[E0277]: the trait bound `std::boxed::Box<[Dummy]>: wasm_bindgen::convert::traits::IntoWasmAbi` is not satisfied
  --> xxxx
   |
XX | #[wasm_bindgen]
   | ^^^^^^^^^^^^^^^ the trait `wasm_bindgen::convert::traits::IntoWasmAbi` is not implemented for `std::boxed::Box<[Dummy]>`
   |
   = help: the following implementations were found:
             <std::boxed::Box<[f32]> as wasm_bindgen::convert::traits::IntoWasmAbi>
             <std::boxed::Box<[f64]> as wasm_bindgen::convert::traits::IntoWasmAbi>
             <std::boxed::Box<[i16]> as wasm_bindgen::convert::traits::IntoWasmAbi>
             <std::boxed::Box<[i32]> as wasm_bindgen::convert::traits::IntoWasmAbi>
           and 9 others
   = note: required because of the requirements on the impl of `wasm_bindgen::convert::traits::IntoWasmAbi` for `std::vec::Vec<Dummy>` …
Run Code Online (Sandbox Code Playgroud)

rust wasm-bindgen

5
推荐指数
1
解决办法
853
查看次数

标签 统计

rust ×1

wasm-bindgen ×1