Skip to main content

oag_core/
lib.rs

1pub mod config;
2pub mod error;
3pub mod ir;
4pub mod parse;
5pub mod transform;
6
7use thiserror::Error;
8
9/// A generated file with path and content.
10#[derive(Debug, Clone)]
11pub struct GeneratedFile {
12    pub path: String,
13    pub content: String,
14}
15
16/// Unified error type for code generators.
17#[derive(Debug, Error)]
18pub enum GeneratorError {
19    #[error("template render failed: {0}")]
20    Render(String),
21
22    #[error("generation failed: {0}")]
23    Other(String),
24}
25
26/// Trait for code generators that produce files from an IR spec.
27pub trait CodeGenerator {
28    fn id(&self) -> config::GeneratorId;
29    fn generate(
30        &self,
31        ir: &ir::IrSpec,
32        config: &config::GeneratorConfig,
33    ) -> Result<Vec<GeneratedFile>, GeneratorError>;
34}