How to return a string (or similar) from Rust in WebAssembly?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I created a small WASM file from this Rust code: #[no_mangle] pub fn hello() -> &'static str { "hello from rust" } It builds and the hello function can be called from JS: My problem is that the alert displays "undefined". If I return a i32 , it works and displays the i32 . I also tried to return a String but it does not work (it still displays "undefined"). Is there a way to return a string from Rust in WebAssembly? What type should I use? 回答1: WebAssembly only supports a few numeric types , which is all that can be returned via an exported