Skip to main content

Crate ridl_backend_rust

Crate ridl_backend_rust 

Source
Expand description

IR v2 package to Rust source plus an extern-C header (ADR-0004 section 7, ADR-0007 decision 13).

The full E1.12 backend over the typl surface. Each declaration in a v2::Package is realized twice: once as idiomatic Rust (the language layer of typl reference Appendix D — every integer is i64, every float is f64) and once, where the C ABI admits it, as an entry in a companion C header. Named scalar types become #[repr(transparent)] newtypes so unit safety survives into generated code (typl reference §5.7); composites map to structs, enums, and Rust enum unions.

Rust source is built as a proc_macro2::TokenStream with quote and formatted with prettyplease, never by shelling out to rustfmt.

Default derivation follows the leaf-recursion rule: an impl Default is emitted for a type only when every field it transitively contains is derivable. The IR InitValue.derivable flag on a composite-typed field is a one-level flag, so same-package composite references are re-checked by recursion rather than trusted (see the defaults module).

Derive eligibility uses the same recursion over the transitive closure, in the derives module: Debug, Clone and PartialEq on every generated type, Copy, Eq, Hash and the ordering pair where the closure permits, and Default never, because it comes from the typl init value instead.

Structs§

GenerateError
A failure to generate code from a package.
Generated
The generated artifact for one package: Rust source.

Enums§

WireEncoding
The payload encoding a generated package’s face encodes and verifies over (design note D-11; ADR-0020 decision 1 names the three encodings).

Functions§

generate
Generates the Rust source for package: the domain types only. The only runtime paths in its output are the ::ridl_rt::payload::Violation and ::ridl_rt::payload::Rule that a named scalar’s constructor (typl value objects, Task 3) and an enum’s or enum set’s TryFrom<i64> (Task 5) name; it emits no interaction face.
generate_face
Generates the Rust source for package: the domain types generate emits, plus the interaction-face descriptors over the ridl-rt runtime crate (Lane M stage M3).
generate_face_with
generate_face with the package’s wire encoding stated rather than defaulted (design note D-11 of docs/archive/2026-09-20-flatbuffers-codec-design.md).
generate_pipeline
The pipeline’s entry point: everything generate_face_with emits, over the whole build, with an interface the face cannot carry skipped rather than refused (E11.14 decisions 1, 2 and 4).
generate_with
generate with the other packages of the same build.
module_segment
The Rust module-segment spelling of one typl package name segment: mod becomes r#mod, crate becomes crate_, and an ordinary segment is returned unchanged.