File tree Expand file tree Collapse file tree 2 files changed +19
-17
lines changed Expand file tree Collapse file tree 2 files changed +19
-17
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 1
1
use error:: ToCompileError ;
2
+ use files:: write_to_file;
2
3
use parsers:: struc:: parse_struct_fields;
3
4
use proc_macro:: TokenStream ;
4
5
use quote:: quote;
5
- use std:: {
6
- fs:: { create_dir_all, write} ,
7
- path:: PathBuf ,
8
- } ;
9
6
use struct_attrs:: StructAttrs ;
10
7
use syn:: { parse_macro_input, DeriveInput } ;
11
8
use ts:: gen_ts_code:: gen_ts_code;
12
9
13
10
mod error;
11
+ mod files;
14
12
mod parsers;
15
13
mod rename_all;
16
14
mod struct_attrs;
@@ -37,16 +35,3 @@ fn handle_derive(input: &DeriveInput) -> anyhow::Result<TokenStream> {
37
35
38
36
Ok ( quote ! { } . into ( ) )
39
37
}
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
- }
You can’t perform that action at this time.
0 commit comments