提问人:UmbrellaMan 提问时间:1/22/2020 更新时间:6/18/2023 访问量:589
wasm_bindgen Rust 中的异步 fn 问题
wasm_bindgen Problem with async fn in 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
法典:
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")
}
答: 暂无答案
评论