/** * Rust code emitter — Declaration IR → Rust source code. * * Replaces `file.rs.njk` + `_macros.njk` (~1,072 lines of Nunjucks templates) * with a typed TypeScript function that walks the FileDecl tree. * * The emitter produces Rust code using the struct + enum pattern for * polymorphic types. Output is post-processed by `cargo fmt`. * * Key Rust-specific patterns: * - Polymorphic types use struct + XxxKind enum (not inheritance) * - Variant-specific fields live on enum variants, not child classes * - Polymorphic single-ref fields → serde_json::Value * - Ownership: String, Option, Vec * - Pattern matching for load/save of variant fields * * Structural blocks emitted (in order): * 1. Header comment (auto-generated warning) * 2. Imports (context, referenced types) * 3. For each polymorphic type: * a. XxxKind enum with inline struct variants * b. impl Default for XxxKind * 4. For each type: * a. Struct definition with #[derive(Debug, Clone, Default)] * b. impl block: * - new(), from_json(), from_yaml() * - load_from_value() * - kind_str() (polymorphic only) * - to_value(), to_json(), to_yaml() * - to_wire() (when wire mappings exist) * - Collection helpers * - Factory methods * - Method stubs (as trait) */ import { FileDecl, TypeDecl } from "../../ir/declarations.js"; import { ExprVisitor } from "../../ir/visitor.js"; /** * Crate-level lint allowances applied to the top of every generated Rust file. * * `unexpected_cfgs` is included so consumers whose Cargo.toml does not declare a * `serde` feature are not warned once per `#[cfg(feature = "serde")]` site. * Rust 1.80+ checks feature cfgs against the crate manifest, so an undeclared * `serde` feature would otherwise emit a warning for each gated item. The lint * has been recognized since Rust 1.51, so allowing it is safe on all supported * toolchains and is a no-op when the feature IS declared (e.g. the rust-serde * target or the fixture harness). */ export declare const RUST_ALLOW_ATTR = "#![allow(unused_imports, dead_code, non_camel_case_types, unused_variables, unexpected_cfgs, clippy::all)]"; export interface RustEmitterOptions { enumParsing?: "case-sensitive" | "case-insensitive"; cancellationTokenPath?: string; nativeSerialization?: "none" | "serde"; } /** * Emit a complete Rust source file from a FileDecl. * * @param file - File declaration to emit * @param visitor - Expression visitor * @param polymorphicTypeNames - Set of type names that have polymorphic dispatch * @param childToParent - Map from child variant name to parent type name */ export declare function emitRustFile(file: FileDecl, visitor: ExprVisitor, polymorphicTypeNames: Set, childToParent?: Map, options?: RustEmitterOptions, declsByName?: Map): string; /** Map a protocol type string to a Rust type. */ export declare function protocolRustType(typeStr: string): string;