Skip to main content

CodecExpr

Enum CodecExpr 

Source
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

Source

pub fn runtime(name: &'static str) -> Self

A member of the core namespace import (r.{name}).

Source

pub fn import_from(module: impl Into<String>, export: impl Into<String>) -> Self

A named import from an arbitrary module.

Source

pub fn type_ref(name: impl Into<String>) -> Self

A reference to a generated type by its Rust name.

Source

pub fn call( callee: CodecExpr, args: impl IntoIterator<Item = CodecExpr>, ) -> Self

A call expression callee(args...).

Source

pub fn object( entries: impl IntoIterator<Item = (impl Into<String>, CodecExpr)>, ) -> Self

An object literal { k: v, ... }.

Source

pub fn array(elements: impl IntoIterator<Item = CodecExpr>) -> Self

An array literal [a, b, ...].

Source

pub fn raw(ts: impl Into<String>) -> Self

Verbatim TypeScript. The generator never inspects the contents.

Source

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.

Source

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).

Source

pub fn max_param(&self) -> Option<usize>

The highest CodecExpr::Param index in the tree, if any.

Source

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.

Trait Implementations§

Source§

impl Clone for CodecExpr

Source§

fn clone(&self) -> CodecExpr

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CodecExpr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for CodecExpr

Source§

impl Hash for CodecExpr

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for CodecExpr

Source§

fn eq(&self, other: &CodecExpr) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CodecExpr

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.