@@ -63,10 +63,21 @@ fn main() {
63
63
let pool = ThreadPool :: new ( ) . unwrap ( ) ;
64
64
let mut tasks = vec ! [ ] ;
65
65
let problems = fetcher:: get_problems ( ) . unwrap ( ) ;
66
- for stat in problems. stat_status_pairs {
66
+ let mut mod_file_addon = vec ! [ ] ;
67
+ for problem_stat in problems. stat_status_pairs {
68
+ mod_file_addon. push ( format ! (
69
+ "mod p{:04}_{};" ,
70
+ problem_stat. stat. frontend_question_id,
71
+ problem_stat
72
+ . stat
73
+ . question_title_slug
74
+ . clone( )
75
+ . unwrap( )
76
+ . replace( "-" , "_" )
77
+ ) ) ;
67
78
tasks. push (
68
79
pool. spawn_with_handle ( async move {
69
- let problem = fetcher:: get_problem_async ( stat ) . await ;
80
+ let problem = fetcher:: get_problem_async ( problem_stat ) . await ;
70
81
if problem. is_none ( ) {
71
82
return ;
72
83
}
@@ -80,12 +91,18 @@ fn main() {
80
91
return ;
81
92
}
82
93
let code = code. unwrap ( ) ;
83
- async { deal_problem ( & problem, & code) } . await
94
+ async { deal_problem ( & problem, & code, false ) } . await
84
95
} )
85
96
. unwrap ( ) ,
86
97
) ;
87
98
}
88
99
block_on ( join_all ( tasks) ) ;
100
+ let mut lib_file = fs:: OpenOptions :: new ( )
101
+ . write ( true )
102
+ . append ( true )
103
+ . open ( "./src/problem/mod.rs" )
104
+ . unwrap ( ) ;
105
+ writeln ! ( lib_file, "{}" , mod_file_addon. join( "\n " ) ) ;
89
106
break ;
90
107
} else {
91
108
id = id_arg
@@ -114,7 +131,7 @@ fn main() {
114
131
continue ;
115
132
}
116
133
let code = code. unwrap ( ) ;
117
- deal_problem ( & problem, & code) ;
134
+ deal_problem ( & problem, & code, true ) ;
118
135
break ;
119
136
}
120
137
}
@@ -278,7 +295,7 @@ fn deal_solving(id: &u32) {
278
295
writeln ! ( lib_file, "mod {};" , solution_name) ;
279
296
}
280
297
281
- fn deal_problem ( problem : & Problem , code : & CodeDefinition ) {
298
+ fn deal_problem ( problem : & Problem , code : & CodeDefinition , write_mod_file : bool ) {
282
299
let file_name = format ! (
283
300
"p{:04}_{}" ,
284
301
problem. question_id,
@@ -310,10 +327,12 @@ fn deal_problem(problem: &Problem, code: &CodeDefinition) {
310
327
file. write_all ( source. as_bytes ( ) ) . unwrap ( ) ;
311
328
drop ( file) ;
312
329
313
- let mut lib_file = fs:: OpenOptions :: new ( )
314
- . write ( true )
315
- . append ( true )
316
- . open ( "./src/problem/mod.rs" )
317
- . unwrap ( ) ;
318
- writeln ! ( lib_file, "mod {};" , file_name) ;
330
+ if write_mod_file {
331
+ let mut lib_file = fs:: OpenOptions :: new ( )
332
+ . write ( true )
333
+ . append ( true )
334
+ . open ( "./src/problem/mod.rs" )
335
+ . unwrap ( ) ;
336
+ writeln ! ( lib_file, "mod {};" , file_name) ;
337
+ }
319
338
}
0 commit comments