Skip to content

Commit

Permalink
fix(ast_codegen): create output path if doesn't exist.
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Aug 1, 2024
1 parent 8bddf90 commit 0151aff
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tasks/ast_codegen/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,13 @@ impl TokenStreamExt for TokenStream {
}
}

pub fn write_all_to<S: AsRef<str>>(data: &[u8], path: S) -> std::io::Result<()> {
pub fn write_all_to<S: AsRef<std::path::Path>>(data: &[u8], path: S) -> std::io::Result<()> {
use std::{fs, io::Write};
let mut file = fs::File::create(path.as_ref())?;
let path = path.as_ref();
if let Some(parent) = path.parent() {
fs::create_dir_all(parent)?;
}
let mut file = fs::File::create(path)?;
file.write_all(data)?;
Ok(())
}

0 comments on commit 0151aff

Please sign in to comment.