Skip to main content

Module bridge

Module bridge 

Source
Expand description

Step 2: scaffold a Rust crate for one unit, with JS bindings and a manifest the later steps read.

The crate splits bindings from logic: src/lib.rs holds thin #[napi] or #[wasm_bindgen] wrappers, src/port.rs holds the port in plain Rust with #![forbid(unsafe_code)], so it can be tested without a JS runtime.

Structs§

JsOnly
Manifest
What bridge generated; every later step starts from it.
Options
Outcome
Refreshed
What refresh rewrote.

Enums§

Allocator
The global allocator of a crate with batches (bridge --allocator).
EndState
What a unit’s bindings are for once the port is done (bridge --end-state).
Kind
RType
A Rust type as seen by the port, from a TS type annotation.

Constants§

MANIFEST
SCHEMA

Functions§

add_batches
Adds batch classes to a bridged crate, then regenerates its bindings.
bridge
class_reason
Why a class has to stay in the source language: its blocker, else the first method (and, for TS/JS, the constructor) that cannot cross. None when it can be bridged.
js_only_reason
Why an export cannot cross a JS/Rust bridge unchanged, if it cannot.
match_export_names
A port function whose doc line does not name an export (/// Port of \Integer.toString``) takes the name of the export it was generated for, matched by its Rust name.
param_type
A parameter’s type for the port, rest and optional parameters included.
refresh
Regenerates the binding layer (lib.rs, index.cjs, js.rs) from the signatures in port.rs, and adds the dependencies they need to Cargo.toml. Never touches port.rs.
resolve_aliases
Replaces simple type aliases (type KeyString = string) by what they stand for.
set_end_state
Records the unit’s end state in its manifest.
snake_case
substitute_constraints
f<T extends string>(s: T) takes a string: type parameters with a simple constraint are replaced by it. The rest stay listed, and keep the function in TS.
substitute_json
Turns the type parameters named in names into unknown (a JSON value on the Rust side).
ts_functions
The exported functions of a TS/JS file with the types bridge judges them by: a sibling .d.ts applied, aliases resolved and generic constraints substituted. analyze counts bridgeable exports from the same list.
types_in_scope
Types declared in file and in the files it imports relatively (one level deep).