Skip to main content

rdbi_codegen/codegen/
mod.rs

1//! Code generation module
2
3mod code_generator;
4mod dao_generator;
5mod naming;
6mod struct_generator;
7mod type_resolver;
8
9pub use code_generator::*;
10pub use naming::*;
11pub use type_resolver::*;
12
13use std::path::Path;
14
15/// Format a generated Rust file in-place using prettyplease.
16///
17/// Uses `syn` to parse and `prettyplease` to format, so it works reliably
18/// without requiring `rustfmt` on PATH (which may not be available during
19/// `cargo build` via build.rs).
20pub(crate) fn format_file(path: &Path) {
21    let Ok(code) = std::fs::read_to_string(path) else {
22        return;
23    };
24    let Ok(parsed) = syn::parse_file(&code) else {
25        return;
26    };
27    let formatted = prettyplease::unparse(&parsed);
28    let _ = std::fs::write(path, formatted);
29}