wasm_bindgen

Attribute Macro wasm_bindgen 

Source
#[wasm_bindgen]
Expand description

The main wasm_bindgen attribute macro.

This macro can be applied to extern "C" blocks to import JavaScript functions and types, using the same syntax as the original wasm-bindgen.

§Example

use wry_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
    // Import a type
    #[wasm_bindgen(extends = Node)]
    pub type Element;

    // Import a method
    #[wasm_bindgen(method, js_name = getAttribute)]
    pub fn get_attribute(this: &Element, name: &str) -> Option<String>;

    // Import a getter
    #[wasm_bindgen(method, getter)]
    pub fn id(this: &Element) -> String;

    // Import a constructor
    #[wasm_bindgen(constructor)]
    pub fn new() -> Element;
}