wasm_bindgen Rust 中的 async fn 问题

Umb*_*Man 9 asynchronous rust

所以我挣扎了一段时间,因为 Rust 编译器不会给我足够的关于这个问题的信息。

我尝试将一个 Rust 库编译成一个 wasm 模块,wasm-pack build --out-dir [dir]但是每次我尝试编译它时都会给我这个错误:

error[E0597]: `*arg0` does not live long enough
  --> src/lib.rs:10:1
   |
10 | #[wasm_bindgen]
   | ^^^^^^^^^^^^^^-
   | |             |
   | |             `*arg0` dropped here while still borrowed
   | borrowed value does not live long enough
   | argument requires that `*arg0` is borrowed for `'static`

error: aborting due to previous error


Run Code Online (Sandbox Code Playgroud)

代码:

use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::JsFuture;
use js_sys;

#[wasm_bindgen]
pub async fn calculation(x:i32,y:i32) -> Result<JsValue,JsValue>{
    let f = js_sys::Promise::resolve(&JsValue::from_str("Mama"));
    let p = wasm_bindgen_futures::JsFuture::from(f).await?;
    Ok((p))
}


#[wasm_bindgen]
pub async fn picture_calculation(picture: &[u8]) -> JsValue{

    JsValue::from_str("Hello")
}


Run Code Online (Sandbox Code Playgroud)