Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ccd52d0

Browse files
committed
write mod file separately
1 parent 0d9c9f9 commit ccd52d0

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

‎src/fetcher.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub struct Problems {
175175

176176
#[derive(Debug, Serialize, Deserialize)]
177177
pub struct StatWithStatus {
178-
stat: Stat,
178+
pubstat: Stat,
179179
difficulty: Difficulty,
180180
paid_only: bool,
181181
is_favor: bool,
@@ -184,19 +184,19 @@ pub struct StatWithStatus {
184184
}
185185

186186
#[derive(Debug, Serialize, Deserialize)]
187-
struct Stat {
187+
pubstruct Stat {
188188
question_id: u32,
189189
#[serde(rename = "question__article__slug")]
190190
question_article_slug: Option<String>,
191191
#[serde(rename = "question__title")]
192192
question_title: Option<String>,
193193
#[serde(rename = "question__title_slug")]
194-
question_title_slug: Option<String>,
194+
pubquestion_title_slug: Option<String>,
195195
#[serde(rename = "question__hide")]
196196
question_hide: bool,
197197
total_acs: u32,
198198
total_submitted: u32,
199-
frontend_question_id: u32,
199+
pubfrontend_question_id: u32,
200200
is_new_question: bool,
201201
}
202202

‎src/main.rs

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,21 @@ fn main() {
6363
let pool = ThreadPool::new().unwrap();
6464
let mut tasks = vec![];
6565
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+
));
6778
tasks.push(
6879
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;
7081
if problem.is_none() {
7182
return;
7283
}
@@ -80,12 +91,18 @@ fn main() {
8091
return;
8192
}
8293
let code = code.unwrap();
83-
async { deal_problem(&problem, &code) }.await
94+
async { deal_problem(&problem, &code,false) }.await
8495
})
8596
.unwrap(),
8697
);
8798
}
8899
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"));
89106
break;
90107
} else {
91108
id = id_arg
@@ -114,7 +131,7 @@ fn main() {
114131
continue;
115132
}
116133
let code = code.unwrap();
117-
deal_problem(&problem, &code);
134+
deal_problem(&problem, &code,true);
118135
break;
119136
}
120137
}
@@ -278,7 +295,7 @@ fn deal_solving(id: &u32) {
278295
writeln!(lib_file, "mod {};", solution_name);
279296
}
280297

281-
fn deal_problem(problem: &Problem, code: &CodeDefinition) {
298+
fn deal_problem(problem: &Problem, code: &CodeDefinition,write_mod_file:bool) {
282299
let file_name = format!(
283300
"p{:04}_{}",
284301
problem.question_id,
@@ -310,10 +327,12 @@ fn deal_problem(problem: &Problem, code: &CodeDefinition) {
310327
file.write_all(source.as_bytes()).unwrap();
311328
drop(file);
312329

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+
}
319338
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /