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.parseis fast in V8), with markers for what JSON lacks (undefined, NaN, lone surrogates; seejs.rs); - UTF-16 units: a
Vec<u16>return, for strings that may hold lone surrogates.
Structs§
- Modules
- PortApi
- What
port.rsoffers to JS.methodspairs each method with whether it takes&mut self. - Port
Class - A port class: a struct with
newand methods taking&selfor&mut self. - PortFn
- A port function, as declared in
port.rs.
Enums§
- Wire
- How a Rust type crosses the bridge.
Constants§
Functions§
- cargo_
toml - ensure_
deps - Adds missing required dependencies to an existing Cargo.toml, keeping everything else.
- guard_
cjs - The last layer of
index.cjs: errors keep their JS class (TypeError: xfrom Rust throws aTypeError), panics carrycode: 'RUST_PANIC', async exports reject instead of throwing, and a string a RustStringcannot hold (a lone surrogate) is refused instead of altered. - index_
cjs - is_
async - lib_rs
- parse_
port - The functions and classes
port.rsoffers. A function’s JS name comes from its/// Port ofnamedoc line (else its Rust name in camelCase); a class is a `pub struct` documented `/// Port of class `Name, with animplholdingnewand its methods. - port_rs
port.rswith one stub per export, typed from the TS signature.- required_
deps - Dependencies the bindings need, as
(name, TOML value). - wire