Skip to main content

bomboni_wasm_core

Core types and utilities for generating TypeScript declarations from Rust types. This crate provides the foundation for the bomboni_wasm derive macro.

Modules

options

Configuration options for the Wasm derive macro.

ts_decl

TypeScript declaration generation.

ts_type

TypeScript type representations.

Options Module

WasmOptions

Configuration options for the Wasm derive macro.
pub struct WasmOptions<'a> {
    pub serde_container: SerdeContainer<'a>,
    pub wasm_bindgen_crate: Option<Path>,
    pub js_sys_crate: Option<Path>,
    pub bomboni_crate: Option<Path>,
    pub bomboni_wasm_crate: Option<Path>,
    pub into_wasm_abi: bool,
    pub from_wasm_abi: bool,
    pub enum_value: bool,
    pub js_value: Option<JsValueWasm>,
    pub proxy: Option<ProxyWasm>,
    pub reference_change: ReferenceChangeMap,
    pub rename: Option<String>,
    pub rename_wrapper: Option<bool>,
    pub rename_all: Option<attr::RenameRule>,
    pub rename_boundary: Vec<Boundary>,
    pub override_type: Option<String>,
    pub fields: Vec<FieldWasm>,
    pub variants: Vec<VariantWasm>,
}

Methods

from_derive_input Creates WasmOptions from a DeriveInput.
pub fn from_derive_input(input: &'a DeriveInput) -> syn::Result<Self>

FieldWasm

WASM options for a struct field.
pub struct FieldWasm {
    pub member: Member,
    pub optional: bool,
    pub reference_change: ReferenceChangeMap,
    pub override_type: Option<String>,
    pub rename_wrapper: Option<bool>,
    pub always_some: Option<bool>,
    pub rename: Option<String>,
}

VariantWasm

WASM options for an enum variant.
pub struct VariantWasm {
    pub ident: Ident,
    pub reference_change: ReferenceChangeMap,
    pub override_type: Option<String>,
    pub rename_wrapper: Option<bool>,
    pub fields: Vec<FieldWasm>,
    pub rename: Option<String>,
}

ReferenceChangeMap

Maps Rust reference types to TypeScript types.
pub struct ReferenceChangeMap {
    pub name: Option<String>,
    pub types: BTreeMap<String, TsType>,
}

JsValueWasm

Configuration for custom JsValue conversions.
pub struct JsValueWasm {
    pub into: Option<Path>,
    pub try_from: Option<Path>,
    pub convert_string: bool,
}

ProxyWasm

Configuration for proxy type WASM bindings.
pub struct ProxyWasm {
    pub proxy: Path,
    pub into: Option<Path>,
    pub try_from: Option<Path>,
}

TypeScript Declaration Module

TsDecl

TypeScript declaration enum.
pub enum TsDecl {
    TypeAlias(TypeAliasTsDecl),
    Interface(InterfaceTsDecl),
    Enum(EnumTsDecl),
}

Methods

name Gets the name of the declaration.
pub fn name(&self) -> &str

TypeAliasTsDecl

TypeScript type alias declaration.
pub struct TypeAliasTsDecl {
    pub name: String,
    pub type_params: Vec<String>,
    pub alias_type: TsType,
}

InterfaceTsDecl

TypeScript interface declaration.
pub struct InterfaceTsDecl {
    pub name: String,
    pub type_params: Vec<String>,
    pub extends: Vec<TsType>,
    pub body: Vec<TsTypeElement>,
}

EnumTsDecl

TypeScript enum declaration.
pub struct EnumTsDecl {
    pub name: String,
    pub type_params: Vec<String>,
    pub members: Vec<TypeAliasTsDecl>,
    pub external_tag: bool,
    pub enum_value: bool,
}

TsDeclParser

Parser for generating TypeScript declarations from Rust types.
pub struct TsDeclParser<'a> {
    options: &'a WasmOptions<'a>,
}

Methods

new Creates a new TypeScript declaration parser.
pub const fn new(options: &'a WasmOptions<'a>) -> Self
parse Parses the Rust type into a TypeScript declaration.
pub fn parse(&self) -> TsDecl

TypeScript Type Module

TsType

TypeScript type representation.
pub enum TsType {
    Keyword(KeywordTsType),
    Literal(String),
    Array(Box<Self>),
    Tuple(Vec<Self>),
    Option(Box<Self>),
    Reference { name: String, type_params: Vec<Self> },
    Fn { params: Vec<Self>, alias_type: Box<Self> },
    TypeLiteral(TypeLiteralTsType),
    Intersection(Vec<Self>),
    Union(Vec<Self>),
    Override(String),
    Partial(Box<Self>),
}

Type Constants

pub const NUMBER: Self;
pub const BIGINT: Self;
pub const BOOLEAN: Self;
pub const STRING: Self;
pub const VOID: Self;
pub const UNDEFINED: Self;
pub const NULL: Self;
pub const NEVER: Self;

Methods

from_type Creates a TypeScript type from a Rust type.
pub fn from_type(value: &Type) -> Self
nullish Gets the nullish type for the current platform.
pub const fn nullish() -> Self
Returns UNDEFINED for JavaScript targets and NULL otherwise. is_reference Checks if the type is a reference type.
pub const fn is_reference(&self) -> bool
get_reference_names Gets all reference names used in this type.
pub fn get_reference_names(&self) -> BTreeSet<String>
with_tag_type Creates a type with the given tag type.
pub fn with_tag_type(self, tag_type: &TagType, name: &str, style: Style) -> Self
intersection Creates an intersection type with another type.
pub fn intersection(self, other: Self) -> Self
change_reference Changes reference names according to the provided map.
pub fn change_reference(self, rename_map: &ReferenceChangeMap) -> Self
rename_protobuf_wrapper Renames protobuf wrapper types to their simplified forms.
pub fn rename_protobuf_wrapper(self) -> Self
Converts:
  • DoubleValue, FloatValuenumber
  • Int64Value, UInt64Valuestring
  • Int32Value, UInt32Valuenumber
  • BoolValueboolean
  • StringValuestring
  • BytesValueUint8Array (JS) or number[]

KeywordTsType

TypeScript keyword types.
pub enum KeywordTsType {
    Number,
    Bigint,
    Boolean,
    String,
    Void,
    Undefined,
    Null,
    Never,
}

TypeLiteralTsType

TypeScript type literal.
pub struct TypeLiteralTsType {
    pub members: Vec<TsTypeElement>,
}

Methods

intersection Creates an intersection with another type literal.
pub fn intersection(self, other: Self) -> Self

TsTypeElement

TypeScript type element.
pub struct TsTypeElement {
    pub key: String,
    pub alias_type: TsType,
    pub optional: bool,
}

Type Mapping

The library automatically maps Rust types to TypeScript types:

Primitive Types

  • u8, u16, u32, u64, usize, i8, i16, i32, i64, isize, f32, f64number
  • u128, i128bigint (with JS feature) or number
  • String, str, char, Path, PathBufstring
  • boolboolean

Container Types

  • Box<T>, Cow<T>, Rc<T>, Arc<T>, Cell<T>, RefCell<T>T
  • Vec<T>, VecDeque<T>, LinkedList<T>, HashSet<T>, BTreeSet<T>T[]
  • HashMap<K, V>, BTreeMap<K, V>Map<K, V> (JS) or Record<K, V>
  • Option<T>T | null or T | undefined
  • ByteBufUint8Array (JS) or number[]

Arrays and Tuples

  • Fixed-size arrays [T; N] where N ≤ 16 → [T, T, ...] (tuple)
  • Larger arrays → T[]
  • () (unit type) → null or undefined

Build docs developers (and LLMs) love