pub enum CodecExpr {
Runtime(&'static str),
Import(Import),
TypeRef(String),
Call(Box<CodecExpr>, Vec<CodecExpr>),
Object(Vec<(String, CodecExpr)>),
Array(Vec<CodecExpr>),
LitInt(u64),
Param(usize),
Raw(String),
}Expand description
A TypeScript codec expression.
Expressions are composed structurally; rendering happens once at
generate time, when all generated type
names are known.
Variants§
Runtime(&'static str)
A member of the core rkyv-js namespace import: Runtime("u32")
renders as r.u32.
Import(Import)
A named import; renders as the bare export name and contributes an entry to the generated import block.
TypeRef(String)
A reference to a generated type by its Rust name. Resolved to the
archived (exported) name at generate() time.
Call(Box<CodecExpr>, Vec<CodecExpr>)
A call expression: callee(args...).
Object(Vec<(String, CodecExpr)>)
An object literal { k: v, ... } — used for enum struct-variant
records.
Array(Vec<CodecExpr>)
An array literal [a, b, ...] — used for enum tuple variants.
LitInt(u64)
An integer literal (array lengths).
Param(usize)
A placeholder inside registry templates, replaced by
substitute.
Raw(String)
Escape hatch: verbatim TypeScript. Never inspected for imports or type references.
Implementations§
Source§impl CodecExpr
impl CodecExpr
Sourcepub fn import_from(module: impl Into<String>, export: impl Into<String>) -> Self
pub fn import_from(module: impl Into<String>, export: impl Into<String>) -> Self
A named import from an arbitrary module.
Sourcepub fn type_ref(name: impl Into<String>) -> Self
pub fn type_ref(name: impl Into<String>) -> Self
A reference to a generated type by its Rust name.
Sourcepub fn call(
callee: CodecExpr,
args: impl IntoIterator<Item = CodecExpr>,
) -> Self
pub fn call( callee: CodecExpr, args: impl IntoIterator<Item = CodecExpr>, ) -> Self
A call expression callee(args...).
Sourcepub fn object(
entries: impl IntoIterator<Item = (impl Into<String>, CodecExpr)>,
) -> Self
pub fn object( entries: impl IntoIterator<Item = (impl Into<String>, CodecExpr)>, ) -> Self
An object literal { k: v, ... }.
Sourcepub fn array(elements: impl IntoIterator<Item = CodecExpr>) -> Self
pub fn array(elements: impl IntoIterator<Item = CodecExpr>) -> Self
An array literal [a, b, ...].
Sourcepub fn raw(ts: impl Into<String>) -> Self
pub fn raw(ts: impl Into<String>) -> Self
Verbatim TypeScript. The generator never inspects the contents.
Sourcepub fn substitute(&self, args: &[CodecExpr]) -> CodecExpr
pub fn substitute(&self, args: &[CodecExpr]) -> CodecExpr
Replace every CodecExpr::Param i with args[i].
Parameters without a matching argument are left in place; the registry checks arity before substituting.
Sourcepub fn visit(&self, f: &mut impl FnMut(&CodecExpr))
pub fn visit(&self, f: &mut impl FnMut(&CodecExpr))
Walk the expression tree in pre-order, calling f on every node.
CodecExpr::Raw contents are never inspected (the node itself is still visited).
Sourcepub fn max_param(&self) -> Option<usize>
pub fn max_param(&self) -> Option<usize>
The highest CodecExpr::Param index in the tree, if any.
Sourcepub fn render(
&self,
archived_names: &BTreeMap<String, String>,
) -> Result<String, DiagnosticKind>
pub fn render( &self, archived_names: &BTreeMap<String, String>, ) -> Result<String, DiagnosticKind>
Render the expression to TypeScript source.
archived_names maps Rust type names to their exported archived names.
A CodecExpr::TypeRef missing from the map produces DiagnosticKind::UnresolvedTypeRef.