Skip to main content

Module codegen

Module codegen 

Source
Expand description

Code generation for a bridge crate: port stubs from TS signatures, and the binding layer (lib.rs, index.cjs) from the port’s Rust signatures.

The binding layer follows port.rs, not the TS: change a port’s types, run rust-anything refresh, and the bindings and loader follow. Values cross three ways:

  • native: strings, numbers, booleans and lists or options of those, with no extra cost;
  • JSON text: anything structured, as one string each way (JSON.parse is fast in V8), with markers for what JSON lacks (undefined, NaN, lone surrogates; see js.rs);
  • UTF-16 units: a Vec<u16> return, for strings that may hold lone surrogates.

Structs§

Modules
PortApi
What port.rs offers to JS. methods pairs each method with whether it takes &mut self.
PortClass
A port class: a struct with new and methods taking &self or &mut self.
PortFn
A port function, as declared in port.rs.

Enums§

Wire
How a Rust type crosses the bridge.

Constants§

JS_RS

Functions§

cargo_toml
ensure_deps
Adds missing required dependencies to an existing Cargo.toml, keeping everything else.
index_cjs
is_async
lib_rs
parse_port
The functions and classes port.rs offers. A function’s JS name comes from its /// Port of name doc line (else its Rust name in camelCase); a class is a `pub struct` documented `/// Port of class `Name, with an impl holding new and its methods.
port_rs
port.rs with one stub per export, typed from the TS signature.
required_deps
Dependencies the bindings need, as (name, TOML value).
wire