getter_with_clone
預設情況下,暴露給 JavaScript 的 Rust 導出會產生需要欄位實作 Copy
的 getter。 getter_with_clone
屬性可用於產生需要 Clone
的 getter。此屬性可以應用於每個結構體或每個欄位。例如:
#![allow(unused)] fn main() { #[wasm_bindgen] pub struct Foo { #[wasm_bindgen(getter_with_clone)] pub bar: String, } #[wasm_bindgen(getter_with_clone)] pub struct Foo { pub bar: String, pub baz: String, } }