Skip to main content

CodegenBackend

Trait CodegenBackend 

Source
pub trait CodegenBackend {
    // Required methods
    fn name(&self) -> &str;
    fn file_extension(&self) -> &str;
    fn generate(
        &self,
        compiled: &CompiledSchema,
    ) -> Result<String, CodegenError>;
    fn generate_project(
        &self,
        result: &ProjectResult,
    ) -> Result<BTreeMap<PathBuf, String>, CodegenError>;
}
Expand description

A pluggable code-generation backend.

Each backend translates compiled Vexil schemas into source code for a specific target language. Implement this trait to add support for a new language.

Backends are used in two modes:

  • Single-file via generate — for REPL, quick checks, or single-schema compilation.
  • Project-level via generate_project — for multi-file projects. The backend owns cross-file import strategy and output file layout.

Required Methods§

Source

fn name(&self) -> &str

Backend identifier, e.g. "rust", "typescript".

Source

fn file_extension(&self) -> &str

File extension for generated files, e.g. "rs", "ts".

Source

fn generate(&self, compiled: &CompiledSchema) -> Result<String, CodegenError>

Generate code for a single compiled schema.

Source

fn generate_project( &self, result: &ProjectResult, ) -> Result<BTreeMap<PathBuf, String>, CodegenError>

Generate all files for a multi-file project.

Returns a map from relative output path to file content. The backend is responsible for cross-file import statements and module-scaffolding files (e.g. mod.rs, index.ts).

Implementors§