Skip to main content

wasm_import

Attribute Macro wasm_import 

Source
#[wasm_import]
Expand description

Declares a block of JavaScript imports, in place of #[wasm_bindgen] on an extern "C" block.

Arguments are forwarded to #[wasm_bindgen], and the attributes inside the block are left for it to read. Each type the block declares also gets the wire traits, so it can appear in a #[wasm_export] signature. Unlike the other macros, #[wasm_bindgen] is applied unconditionally: an extern block cannot compile without it, so the block’s own cfg decides.

ⓘ
#[wasm_import]
extern "C" {
    #[wasm_bindgen(js_name = SharedUnlockDriver)]
    pub type RawJsSharedUnlockDriver;

    #[wasm_bindgen(method, catch)]
    async fn lock_user(this: &RawJsSharedUnlockDriver, user_id: String) -> Result<(), JsValue>;
}