Skip to content

WebAssembly

· 1 min

Rust#

数组和对象传递#

// let array = [1,2,3,4,5,6,7,8,9];
pub fn test(array: JsValue) {
let elements: Vec<u32> = array.into_serde().unwrap();
}
#[derive(Serialize, Deserialize)]
pub struct Element {
name: String,
id: String,
parent_id: String,
}
// let js_object = {name: "hello world", id: "99", parent_id: "11"};
pub fn test(js_object: &JsValue) {
let element: Element = js_object.into_serde().unwrap();
}

https://www.coder.work/article/2554080

闭包问题#

https://cloud.tencent.com/developer/ask/sof/765656

https://stackoverflow.com/questions/53214434/how-to-return-a-rust-closure-to-javascript-via-webassembly/53219594#53219594

资料#

Rust 🦀 和 WebAssembly 🕸

wasm-bindgen 指南