Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
504 views
in Technique[技术] by (71.8m points)

rust - The trait `IntoWasmAbi` is not implemented for `HashMap<i32, i32>

Trying to compile following rust code to wasm to make it compatible running with existing js. Trying to return hashmaped value from function.

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 
    }

Console error after running command 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"

Is there any way to achieve this ?

question from:https://stackoverflow.com/questions/65558037/the-trait-intowasmabi-is-not-implemented-for-hashmapi32-i32

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...