将 JSON 作为 HashMap 从 Javascript 传递到 Rust 编译的 WebAssembly
如何将 JSON 对象从 JS 传递到 Rust 函数?所有具有键值对的 JSON 对象都必须先序列化,然后才能将其传递到从已编译的 WASM 导出的函数的调用中吗? (例如,仅原始类型、字符串或整数)
可以轻松地调用传递字符串的函数,而接收端的 Rust 需要 &str
类型。但是,我不知道如何指定 JSON 对象的类型。使用 HashMap<&str, &str>
会导致 wasm-bindgen
出错,消息如下:
the trait `wasm_bindgen::convert::FromWasmAbi` is not implemented for `std::collections::HashMap<&str, &str>`
How could I pass a JSON object from JS to a Rust function? Must all JSON objects with key value pairs be serialised before passing it in a call to an exported function from the compiled WASM? (Just primitive types, strings or integers for example)
Functions can be called passing a string easily, with Rust on the receiving end expecting a &str
type. However, I can't figure out how I might specify the type for a JSON object. Using HashMap<&str, &str>
results in an error with wasm-bindgen
, with the message as follows:
the trait `wasm_bindgen::convert::FromWasmAbi` is not implemented for `std::collections::HashMap<&str, &str>`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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