未为 `HashMap<i32, i32> 实现特性 `IntoWasmAbi`

问题描述

尝试将以下 rust 代码编译为 wasm 以使其与现有 js 兼容运行。试图从函数返回哈希映射值。

lib.rs

    use wasm_bindgen::prelude::*;
    use std::collections::HashMap;

   #[wasm_bindgen]
    pub fn get_transformed_filters()-> HashMap<i32,i32> { 
        let mut hm = HashMap::new();
        for i in 1..9990000 {
            hm.insert(i + i,i * i);
        }  
        return hm 
    }

运行命令 wasm-pack build 后控制台错误

[INFO]: ?  Checking for the Wasm target...
[INFO]: ?  Compiling to Wasm...
   Compiling hello-wasm v0.1.0 (/Users/mfe/ui/rustService/test-wasm)
error[E0277]: the trait bound `HashMap<i32,i32>: IntoWasmAbi` is not satisfied
  --> src/lib.rs:15:1
   |
15 | #[wasm_bindgen]
   | ^^^^^^^^^^^^^^^ the trait `IntoWasmAbi` is not implemented for `HashMap<i32,i32>`
   |
   = note: required because of the requirements on the impl of `ReturnWasmAbi` for `HashMap<i32,i32>`
   = note: this error originates in an attribute macro (in Nightly builds,run with -Z macro-backtrace for more info)

error: aborting due to prevIoUs error

For more information about this error,try `rustc --explain E0277`.
error: Could not compile `test-wasm`

To learn more,run the command again with --verbose.
Error: Compiling your crate to WebAssembly Failed
Caused by: Failed to execute `cargo build`: exited with exit code: 101
  full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unkNown-unkNown"

有什么办法可以实现吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...