diff --git a/aya-gen/src/lib.rs b/aya-gen/src/lib.rs index e635cd31..d0126863 100644 --- a/aya-gen/src/lib.rs +++ b/aya-gen/src/lib.rs @@ -1,5 +1,5 @@ use std::{ - fs::File, + fs::{create_dir_all, File}, io::{self, Write}, path::Path, }; @@ -10,10 +10,16 @@ pub mod getters; pub mod rustfmt; pub fn write_to_file>(path: T, code: &str) -> Result<(), io::Error> { + if let Some(parent) = path.as_ref().parent() { + create_dir_all(parent)?; + } let mut file = File::create(path)?; file.write_all(code.as_bytes()) } pub fn write_to_file_fmt>(path: T, code: &str) -> Result<(), io::Error> { + if let Some(parent) = path.as_ref().parent() { + create_dir_all(parent)?; + } write_to_file(path, &rustfmt::format(code)?) }