Skip to main content

Module typemap

Module typemap 

Source
Expand description

TypeRef → syn::Type mapping with unified position-based system.

Follows the wasm-bindgen WebIDL approach: a single to_syn_type function that uses TypePosition to determine how types are lowered to Rust.

TypePosition is a struct with two fields:

  • direction: Argument or Return — controls borrowing (e.g., &str vs String)
  • inner: whether we’re nested inside a generic container (e.g., Promise<T>)

When inner is true:

  • Primitives map to JS wrapper types (Number, JsString, Boolean, Undefined)
  • Nullable becomes JsOption<T> instead of Option<T>
  • Argument-position types are NOT borrowed (owned T, not &T)

Structs§

CodegenContext
Context for codegen that tracks locally-defined types and resolved type aliases.
TypePosition
Position context for type mapping, following the wasm-bindgen WebIDL pattern.

Enums§

Direction
Direction of data flow at the FFI boundary.

Constants§

JS_SYS_RESERVED
js_sys type names reserved by the use js_sys::* glob import. User-defined types that collide with these will be renamed.

Functions§

to_return_type
Map an IR TypeRef to the type used in a wasm_bindgen return position, wrapping in Result<T, JsValue> when catch is true.
to_syn_type
Map an IR TypeRef to a proc_macro2::TokenStream representing the Rust type.