pub struct JsonWireTypes<'a> { /* private fields */ }Expand description
Registers Rust “wire type” mirrors for a fully-flattened internally-tagged enum and every struct reachable from its payloads, so a binding backend can re-case the JSON passthrough path from core’s snake_case to JavaScript’s camelCase (and back) with no hand-written per-field conversion code.
declarations() never observes non-determinism: every internal collection is a BTreeMap/
BTreeSet, and a type is visited (and therefore declared) exactly once per [Family] no
matter how many enums or fields reference it, which also makes self-referential and mutually
recursive payload graphs terminate instead of recursing forever.
Implementations§
Source§impl<'a> JsonWireTypes<'a>
impl<'a> JsonWireTypes<'a>
Sourcepub fn new(api: &'a ApiSurface, prefix: &str) -> Self
pub fn new(api: &'a ApiSurface, prefix: &str) -> Self
prefix is the binding’s type prefix, e.g. "Js" or "Wasm"; it is folded into every
emitted name (including the shared absent-predicate helper) so napi- and wasm-generated
wire types can never collide if both are ever generated into one crate.
Sourcepub fn register_enum(&mut self, enum_def: &EnumDef) -> (String, String)
pub fn register_enum(&mut self, enum_def: &EnumDef) -> (String, String)
Register an enum and everything reachable from its payloads. Returns
(out_enum_type_name, in_enum_type_name).
Sourcepub fn core_to_js_value_expr(
&self,
enum_def: &EnumDef,
core_expr: &str,
) -> String
pub fn core_to_js_value_expr( &self, enum_def: &EnumDef, core_expr: &str, ) -> String
Rust expression producing the JavaScript-facing serde_json::Value for a core value.
core_expr must evaluate to something borrowable as the core enum.
Sourcepub fn js_value_to_core_expr(
&self,
enum_def: &EnumDef,
js_expr: &str,
core_path: &str,
) -> String
pub fn js_value_to_core_expr( &self, enum_def: &EnumDef, js_expr: &str, core_path: &str, ) -> String
Rust expression producing the core value from a JavaScript-facing serde_json::Value.
core_path is the fully qualified core type path.
Sourcepub fn retag_fn_name(&self) -> &str
pub fn retag_fn_name(&self) -> &str
The name of the shared top-level-tag retag helper this instance declares (see
JsonWireTypes::new). Exposed so a backend whose own JS boundary is not
serde_json::Value (e.g. wasm’s JsValue, via serde_wasm_bindgen) can rebuild
[out_pipeline_expr]/[in_pipeline_expr] itself from plain string pieces at a call site
that only has a field name and type in hand, not a live &EnumDef – see
codegen::conversions::core_to_binding::fields’s wasm camelCase-recasing helpers for the
concrete caller. ~keep
Sourcepub fn declarations(&self) -> Vec<String>
pub fn declarations(&self) -> Vec<String>
Every emitted Rust declaration, in deterministic (sorted-by-name) order.
Auto Trait Implementations§
impl<'a> Freeze for JsonWireTypes<'a>
impl<'a> RefUnwindSafe for JsonWireTypes<'a>
impl<'a> Send for JsonWireTypes<'a>
impl<'a> Sync for JsonWireTypes<'a>
impl<'a> Unpin for JsonWireTypes<'a>
impl<'a> UnsafeUnpin for JsonWireTypes<'a>
impl<'a> UnwindSafe for JsonWireTypes<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more