Skip to content

Commit f58dae1

Browse files
committed
chore(clippy): make clippy happy
1 parent 024e49a commit f58dae1

File tree

7 files changed

+20
-35
lines changed

7 files changed

+20
-35
lines changed

src/cache/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@ pub fn conn(p: String) -> SqliteConnection {
2323

2424
/// Condition submit or test
2525
#[derive(Clone, Debug)]
26+
#[derive(Default)]
2627
pub enum Run {
2728
Test,
29+
#[default]
2830
Submit,
2931
}
3032

31-
impl Default for Run {
32-
fn default() -> Self {
33-
Run::Submit
34-
}
35-
}
3633

3734
/// Requests if data not download
3835
#[derive(Clone)]

src/cache/parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ pub fn problem(problems: &mut Vec<Problem>, v: Value) -> Option<()> {
1515
// Handle on leetcode-com
1616
Some(s) => s as i32,
1717
// Handle on leetcode-cn
18-
None => fid_obj.as_str()?.split(" ").last()?.parse::<i32>().ok()?,
18+
None => fid_obj.as_str()?.split(' ').last()?.parse::<i32>().ok()?,
1919
};
2020

2121
problems.push(Problem {
2222
category: v.get("category_slug")?.as_str()?.to_string(),
23-
fid: fid,
23+
fid,
2424
id: stat.get("question_id")?.as_i64()? as i32,
2525
level: p.get("difficulty")?.as_object()?.get("level")?.as_i64()? as i32,
2626
locked: p.get("paid_only")?.as_bool()?,
@@ -102,7 +102,7 @@ pub fn daily(v: Value) -> Option<i32> {
102102
// Handle on leetcode-com
103103
Some(v) => v,
104104
// Handle on leetcode-cn
105-
None => v_obj.get("todayRecord")?.as_array()?.get(0)?,
105+
None => v_obj.get("todayRecord")?.as_array()?.first()?,
106106
}
107107
.as_object()?
108108
.get("question")?

src/cmds/list.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ impl Command for ListCommand {
184184
.get_many::<i32>("range")
185185
.ok_or(Error::NoneError)?
186186
.copied()
187-
.into_iter()
188187
.collect();
189188
ps.retain(|x| num_range[0] <= x.fid && x.fid <= num_range[1]);
190189
}

src/cmds/pick.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,8 @@ impl Command for PickCommand {
139139
let fid = match m.contains_id("name") {
140140
// check for name specified, or closest name
141141
true => {
142-
match m.get_one::<String>("name").map(|name| name) {
143-
Some(quesname) => match closest_named_problem(&problems, quesname) {
144-
Some(p) => p,
145-
None => 1,
146-
},
142+
match m.get_one::<String>("name") {
143+
Some(quesname) => closest_named_problem(&problems, quesname).unwrap_or(1),
147144
None => {
148145
// Pick random without specify id
149146
let problem = &problems[rand::thread_rng().gen_range(0..problems.len())];
@@ -190,7 +187,7 @@ fn closest_named_problem(problems: &Vec<Problem>, lookup_name: &str) -> Option<i
190187
let mut table: Vec<usize> = vec![0; (max_name_size + 1) * (lookup_name.len() + 1)];
191188

192189
// this is guaranteed because of the earlier max None propegation
193-
assert!(problems.len() > 0);
190+
assert!(!problems.is_empty());
194191
let mut max_score = 0;
195192
let mut current_problem = &problems[0];
196193
for problem in problems {
@@ -204,7 +201,7 @@ fn closest_named_problem(problems: &Vec<Problem>, lookup_name: &str) -> Option<i
204201

205202
if this_score > max_score {
206203
max_score = this_score;
207-
current_problem = &problem;
204+
current_problem = problem;
208205
}
209206
}
210207

src/cmds/stat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl Command for StatCommand {
8181
);
8282

8383
// lines
84-
for (i, l) in vec![(easy, easy_ac), (medium, medium_ac), (hard, hard_ac)]
84+
for (i, l) in [(easy, easy_ac), (medium, medium_ac), (hard, hard_ac)]
8585
.iter()
8686
.enumerate()
8787
{

src/config/storage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl Storage {
6565
self.scripts = Some("scripts".into());
6666
}
6767

68-
let p = PathBuf::from(root).join(&self.scripts.ok_or(Error::NoneError)?);
68+
let p = PathBuf::from(root).join(self.scripts.ok_or(Error::NoneError)?);
6969
if !PathBuf::from(&p).exists() {
7070
std::fs::create_dir(&p)?
7171
}

src/plugins/leetcode.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,13 @@ impl LeetCode {
8686
json.insert("variables", r#"{"slug": "$slug"}"#.replace("$slug", slug));
8787
json.insert(
8888
"query",
89-
vec![
90-
"query getTopicTag($slug: String!) {",
89+
["query getTopicTag($slug: String!) {",
9190
" topicTag(slug: $slug) {",
9291
" questions {",
9392
" questionId",
9493
" }",
9594
" }",
96-
"}",
97-
]
95+
"}"]
9896
.join("\n"),
9997
);
10098

@@ -151,31 +149,27 @@ impl LeetCode {
151149
json.insert("operationName", "daily".to_string());
152150
json.insert(
153151
"query",
154-
vec![
155-
"query daily {",
152+
["query daily {",
156153
" activeDailyCodingChallengeQuestion {",
157154
" question {",
158155
" questionFrontendId",
159156
" }",
160157
" }",
161-
"}",
162-
]
158+
"}"]
163159
.join("\n"),
164160
);
165161
}
166162
config::LeetcodeSite::LeetcodeCn => {
167163
json.insert("operationName", "questionOfToday".to_string());
168164
json.insert(
169165
"query",
170-
vec![
171-
"query questionOfToday {",
166+
["query questionOfToday {",
172167
" todayRecord {",
173168
" question {",
174169
" questionFrontendId",
175170
" }",
176171
" }",
177-
"}",
178-
]
172+
"}"]
179173
.join("\n"),
180174
);
181175
}
@@ -201,8 +195,7 @@ impl LeetCode {
201195
let mut json: Json = HashMap::new();
202196
json.insert(
203197
"query",
204-
vec![
205-
"query getQuestionDetail($titleSlug: String!) {",
198+
["query getQuestionDetail($titleSlug: String!) {",
206199
" question(titleSlug: $titleSlug) {",
207200
" content",
208201
" stats",
@@ -213,8 +206,7 @@ impl LeetCode {
213206
" metaData",
214207
" translatedContent",
215208
" }",
216-
"}",
217-
]
209+
"}"]
218210
.join("\n"),
219211
);
220212

@@ -232,7 +224,7 @@ impl LeetCode {
232224
json: Some(json),
233225
mode: Mode::Post,
234226
name: "get_problem_detail",
235-
url: self.conf.sys.urls.graphql.into(),
227+
url: self.conf.sys.urls.graphql,
236228
}
237229
.send(&self.client)
238230
.await

0 commit comments

Comments
 (0)