在使用wasm-bindgen时,可以通过使用#[wasm_bindgen(skip)]
属性来让它忽略impl中的某些公共函数。这个属性可以应用于函数、方法、结构体、枚举等元素上,用于指示wasm-bindgen不要将其绑定到WebAssembly模块中。
下面是一个示例:
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub struct MyStruct {
#[wasm_bindgen(skip)]
pub ignored_function: fn(),
pub other_function: fn(),
}
#[wasm_bindgen]
impl MyStruct {
#[wasm_bindgen(skip)]
pub fn ignored_method(&self) {
// This method will be ignored by wasm-bindgen
}
pub fn other_method(&self) {
// This method will be bound to WebAssembly module
}
}
在上面的示例中,ignored_function
和ignored_method
都被标记为#[wasm_bindgen(skip)]
,因此它们不会被绑定到WebAssembly模块中。而other_function
和other_method
则会被绑定到WebAssembly模块中,可以通过JavaScript调用。
关于wasm-bindgen的更多信息和用法,请参考腾讯云的产品介绍链接地址:wasm-bindgen产品介绍
领取专属 10元无门槛券
手把手带您无忧上云