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
bridgegenerated; every later step starts from it. - Options
- Outcome
- Refreshed
- What
refreshrewrote.
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§
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.
Nonewhen 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 inport.rs, and adds the dependencies they need to Cargo.toml. Never touchesport.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
namesintounknown(a JSON value on the Rust side). - ts_
functions - The exported functions of a TS/JS
filewith the typesbridgejudges them by: a sibling.d.tsapplied, aliases resolved and generic constraints substituted.analyzecounts bridgeable exports from the same list. - types_
in_ scope - Types declared in
fileand in the files it imports relatively (one level deep).