pub mod portable;
use std::collections::BTreeMap;
use std::path::PathBuf;
use crate::ir::CompiledSchema;
use crate::project::ProjectResult;
pub trait CodegenBackend {
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>;
}
#[derive(Debug, thiserror::Error)]
pub enum CodegenError {
#[error("unsupported type `{type_name}` in {backend} backend")]
UnsupportedType {
type_name: String,
backend: String,
},
#[error("missing required annotation `{annotation}` ({context})")]
MissingAnnotation {
annotation: String,
context: String,
},
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("backend error: {0}")]
BackendSpecific(Box<dyn std::error::Error + Send + Sync>),
}