Skip to main content

Module enums

Module enums 

Source
Expand description

Enum code generation: string enums and numeric enums.

String enums use wasm_bindgen’s native string enum support:

#[wasm_bindgen]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum QueueContentType {
    #[wasm_bindgen(js_name = "text")]
    Text,
    #[wasm_bindgen(js_name = "bytes")]
    Bytes,
}

Numeric enums use #[repr(u32)] or #[repr(i32)] (selected based on discriminant values) with wasm_bindgen:

#[wasm_bindgen]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum ImportType {
    Static = 1,
    Dynamic = 2,
    ImportMeta = 3,
}

Functions§

generate_numeric_enum
Generate a wasm_bindgen numeric enum with automatically selected repr.
generate_string_enum
Generate a wasm_bindgen string enum.