#wasm-bindgen #serialization #hash-map #macro #read #deserialize #tsify #uint8-array

wasm-bindgen-utils

Provides utilities and helpers that make working with wasm-bindgen easy

31 releases

new 0.0.12-alpha.20 May 14, 2026
0.0.11 May 12, 2026
0.0.10 Jun 7, 2025
0.0.8 May 9, 2025
0.0.6 Feb 17, 2025

#1440 in Encoding

Download history 690/week @ 2026-01-24 414/week @ 2026-01-31 430/week @ 2026-02-07 436/week @ 2026-02-14 419/week @ 2026-02-21 307/week @ 2026-02-28 621/week @ 2026-03-07 219/week @ 2026-03-14 182/week @ 2026-03-21 101/week @ 2026-03-28 101/week @ 2026-04-04 407/week @ 2026-04-11 101/week @ 2026-04-18 129/week @ 2026-04-25 164/week @ 2026-05-02 387/week @ 2026-05-09

786 downloads per month
Used in rain-math-float

LicenseRef-DCL-1.0

48KB
759 lines

wasm-bindgen-utils

Provides utilities, helpers and macros to easily build and customize wasm_bindgen bindings. For more details please read the doumentation of the items of this lib.

Example:

use wasm_bindgen_utils::{prelude::*, impl_wasm_traits, impl_custom_tsify, add_ts_content};

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SomeType {
    #[cfg_attr(target_family = "wasm", serde(serialize_with = "serialize_as_bytes"))]
    pub field: Vec<u8>,
    #[cfg_attr(target_family = "wasm", serde(serialize_with = "serialize_hashmap_as_object"))]
    pub other_field: HashMap<String, u8>,
}

// impl wasm traits for SomeType
impl_wasm_traits!(SomeType);

// impl tsify manually for SomeType (as an alternative to Tsify derive macro)
// the given string literal will become the typescript interface bindings for SomeType
impl_custom_tsify!(
    SomeType,
    "export interface SomeType {
        field: Uint8Array;
        otherField: Record<string, number>;
    }"
);

// appends a custom section to the .d.ts generated bindings
add_ts_content!("import { Something } from 'some-js-lib'")

// now someType can be used on functions and methods natively
#[wasm_bindgen]
pub fn some_fn(arg: SomeType) -> String {
    // body
}

#[wasm_bindgen]
pub async fn some_other_fn(arg1: Vec<u8>, arg2: HashMap<String, u8>) -> Result<SomeType, Error> {
    // body
    Ok(SomeType {
        field: arg1,
        other_field: arg2
    })
}

Dependencies

~1.2–2.3MB
~39K SLoC