Skip to content

Commit c8f8d09

Browse files
committed
files
1 parent 4c1de31 commit c8f8d09

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

crates/macros/src/files.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use std::{
2+
fs::{create_dir_all, write},
3+
path::PathBuf,
4+
};
5+
6+
pub fn write_to_file(path: &PathBuf, content: &str) -> anyhow::Result<()> {
7+
let parent = path.parent().ok_or(anyhow::anyhow!(
8+
"Failed to get parent directory of path: {}",
9+
path.display()
10+
))?;
11+
12+
create_dir_all(parent)?;
13+
14+
write(path, content)?;
15+
16+
Ok(())
17+
}

crates/macros/src/lib.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
use error::ToCompileError;
2+
use files::write_to_file;
23
use parsers::struc::parse_struct_fields;
34
use proc_macro::TokenStream;
45
use quote::quote;
5-
use std::{
6-
fs::{create_dir_all, write},
7-
path::PathBuf,
8-
};
96
use struct_attrs::StructAttrs;
107
use syn::{parse_macro_input, DeriveInput};
118
use ts::gen_ts_code::gen_ts_code;
129

1310
mod error;
11+
mod files;
1412
mod parsers;
1513
mod rename_all;
1614
mod struct_attrs;
@@ -37,16 +35,3 @@ fn handle_derive(input: &DeriveInput) -> anyhow::Result<TokenStream> {
3735

3836
Ok(quote! {}.into())
3937
}
40-
41-
fn write_to_file(path: &PathBuf, content: &str) -> anyhow::Result<()> {
42-
let parent = path.parent().ok_or(anyhow::anyhow!(
43-
"Failed to get parent directory of path: {}",
44-
path.display()
45-
))?;
46-
47-
create_dir_all(parent)?;
48-
49-
write(path, content)?;
50-
51-
Ok(())
52-
}

0 commit comments

Comments
 (0)