use std::path::Path;
pub(crate) struct GeneratedFile {
pub path: std::path::PathBuf,
pub content: String,
}
pub(crate) fn write_file(file: &GeneratedFile) -> Result<String, String> {
super::naming::ensure_missing(&file.path)?;
if let Some(parent) = file.path.parent() {
std::fs::create_dir_all(parent)
.map_err(|e| format!("cannot create directory {}: {e}", parent.display()))?;
}
std::fs::write(&file.path, &file.content)
.map_err(|e| format!("cannot write {}: {e}", file.path.display()))?;
Ok(format!("created {}", file.path.display()))
}
pub(crate) fn module_mod_rs(src_root: &Path, module: &str) -> std::path::PathBuf {
src_root.join(module).join("mod.rs")
}