Skip to main content

neutrino_schema/codegen/
output.rs

1use std::path::PathBuf;
2
3/// A single file produced by a code generator.
4#[derive(Debug, Clone)]
5pub struct GeneratedFile {
6    /// Relative path (e.g. `"users.rs"`, `"enums.rs"`, `"mod.rs"`).
7    pub path: PathBuf,
8    /// File content.
9    pub content: String,
10    /// If `false`, skip writing when target file already exists.
11    pub overwrite: bool,
12}
13
14/// The complete output of a code generator.
15///
16/// Generators return this struct.
17/// The CLI is responsible for writing the files via [`OutputWriter`](crate::OutputWriter).
18#[derive(Debug, Clone)]
19pub struct GeneratedOutput {
20    pub files: Vec<GeneratedFile>,
21}
22
23impl GeneratedOutput {
24    /// Look up a generated file by its relative path.
25    pub fn file(&self, path: &str) -> Option<&GeneratedFile> {
26        self.files.iter().find(|f| f.path == std::path::Path::new(path))
27    }
28}