Wasm Derive Macro
TheWasm derive macro is the foundation of TypeScript binding generation in Bomboni. It automatically generates:
- TypeScript type declarations
- wasm-bindgen integration code
- Conversion traits (
FromWasmAbi,IntoWasmAbi, etc.) - Error handling for WASM conversions
Basic Usage
Struct Attributes
The#[wasm(...)] attribute provides extensive customization options:
ABI Generation
Control which WASM ABI traits are generated:into_wasm_abi- GenerateIntoWasmAbifor Rust → JavaScript conversionfrom_wasm_abi- GenerateFromWasmAbifor JavaScript → Rust conversionwasm_abi- Enable both directions
Renaming
Customize type and field names in TypeScript:Rename All Fields
Apply a naming convention to all fields:camelCase- Convert to camelCasePascalCase- Convert to PascalCasesnake_case- Convert to snake_caseSCREAMING_SNAKE_CASE- Convert to SCREAMING_SNAKE_CASEkebab-case- Convert to kebab-caseSCREAMING-KEBAB-CASE- Convert to SCREAMING-KEBAB-CASE
Override Type
Replace the generated TypeScript type entirely:Field Attributes
Rename Individual Fields
Override Field Types
Always Some
Force optional fields to be non-optional in TypeScript:Type Mapping
Basic Type Mapping
Bomboni automatically maps Rust types to TypeScript:Numeric Types
BigInt Types (with js feature)
Collections
Options
Reference Type Mapping
Change how reference types are mapped:Wrapper Type Renaming
Rename protobuf wrapper types to primitive types:DoubleValue→numberFloatValue→numberInt32Value→numberUInt32Value→numberInt64Value→stringUInt64Value→stringBoolValue→booleanStringValue→stringBytesValue→Uint8Arrayornumber[]
Enum Support
Externally Tagged Enums
Internally Tagged Enums
Adjacently Tagged Enums
Enum Value Objects
Generate JavaScript enum-like objects:Tsify Compatibility
Bomboni’sWasm derive is inspired by and compatible with tsify. The implementation in bomboni_wasm_derive/src/wasm.rs includes:
- Additional proxy type support
- Custom
JsValueconversion options - Enum value object generation
- Reference type mapping
- Wrapper type renaming for protobuf types