Skip to content

Commit 75eb3b7

Browse files
committed
format code with clippy
1 parent 13a37a5 commit 75eb3b7

File tree

13 files changed

+71
-68
lines changed

13 files changed

+71
-68
lines changed

src/cache/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Cache {
7575
/// Get problem
7676
pub fn get_problem(&self, rfid: i32) -> Result<Problem, Error> {
7777
let p: Problem = problems.filter(fid.eq(rfid)).first(&self.conn()?)?;
78-
if p.category != "algorithms".to_string() {
78+
if p.category != "algorithms" {
7979
return Err(Error::FeatureError(
8080
"Not support database and shell questions for now".to_string(),
8181
));
@@ -98,6 +98,7 @@ impl Cache {
9898
}
9999

100100
/// Get question
101+
#[allow(clippy::useless_let_if_seq)]
101102
pub fn get_question(&self, rfid: i32) -> Result<Question, Error> {
102103
let target: Problem = problems.filter(fid.eq(rfid)).first(&self.conn()?)?;
103104

@@ -115,7 +116,7 @@ impl Cache {
115116
"is on the run...".dimmed()
116117
);
117118

118-
if target.category != "algorithms".to_string() {
119+
if target.category != "algorithms" {
119120
return Err(Error::FeatureError(
120121
"Not support database and shell questions for now".to_string(),
121122
));
@@ -128,7 +129,7 @@ impl Cache {
128129
}
129130

130131
let mut rdesc = Question::default();
131-
if target.desc.len() > 0 {
132+
if !target.desc.is_empty() {
132133
rdesc = serde_json::from_str(&target.desc)?;
133134
} else {
134135
let json: Value = self.0.clone().get_question_detail(&target.slug)?.json()?;
@@ -193,7 +194,7 @@ impl Cache {
193194

194195
// pass manually data
195196
json.insert("name", p.name.to_string());
196-
json.insert("data_input", d.case.to_string());
197+
json.insert("data_input", d.case);
197198

198199
let url = match run {
199200
Run::Test => conf.sys.urls.get("test")?.replace("$slug", &p.slug),

src/cache/models.rs

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ pub struct Problem {
2929
pub desc: String,
3030
}
3131

32-
static DONE: &'static str = " ✔";
33-
static ETC: &'static str = "...";
34-
static LOCK: &'static str = "🔒";
35-
static NDONE: &'static str = "✘";
36-
static SPACE: &'static str = " ";
32+
static DONE: &str = " ✔";
33+
static ETC: &str = "...";
34+
static LOCK: &str = "🔒";
35+
static NDONE: &str = "✘";
36+
static SPACE: &str = " ";
3737
impl std::fmt::Display for Problem {
3838
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3939
let space_2 = SPACE.repeat(2);
@@ -46,7 +46,7 @@ impl std::fmt::Display for Problem {
4646
if self.locked {
4747
lock = LOCK
4848
};
49-
if self.status == "ac".to_string() {
49+
if self.status == "ac" {
5050
done = DONE.green().bold();
5151
} else if self.status == "notac" {
5252
done = NDONE.green().bold();
@@ -76,7 +76,7 @@ impl std::fmt::Display for Problem {
7676
}
7777
}
7878

79-
if &self.name.len() < &60_usize {
79+
if self.name.len() < 60_usize {
8080
name.push_str(&self.name);
8181
name.push_str(&SPACE.repeat(60 - &self.name.len()));
8282
} else {
@@ -246,24 +246,25 @@ impl std::fmt::Display for VerifyResult {
246246
debug!("{:#?}", &self);
247247

248248
match &self.status.status_code {
249-
10 => match self.correct_answer {
250-
// Pass Test
251-
true => write!(
252-
f,
253-
"\n {}{}{}\n{}{}{}{}{}{}\n",
254-
&self.status.status_msg.green().bold(),
255-
" Runtime: ".dimmed(),
256-
&self.status.status_runtime.dimmed(),
257-
"\n Your input: ",
258-
&self.data_input.replace("\n", ", "),
259-
"\n Output: ",
260-
ca,
261-
"\n Expected: ",
262-
eca,
263-
),
264-
false => match &self.submit.compare_result.len() > &0 {
249+
10 => {
250+
if self.correct_answer {
251+
// Pass Test
252+
write!(
253+
f,
254+
"\n {}{}{}\n{}{}{}{}{}{}\n",
255+
&self.status.status_msg.green().bold(),
256+
" Runtime: ".dimmed(),
257+
&self.status.status_runtime.dimmed(),
258+
"\n Your input: ",
259+
&self.data_input.replace("\n", ", "),
260+
"\n Output: ",
261+
ca,
262+
"\n Expected: ",
263+
eca,
264+
)
265+
} else if !self.submit.compare_result.is_empty() {
265266
// Submit Successfully
266-
true => write!(
267+
write!(
267268
f,
268269
"\n{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}.\n",
269270
" Success\n\n".green().bold(),
@@ -296,9 +297,10 @@ impl std::fmt::Display for VerifyResult {
296297
&self.pretty_lang,
297298
" online submissions for ",
298299
&self.name,
299-
),
300+
)
301+
} else {
300302
// Wrong Answer
301-
false => write!(
303+
write!(
302304
f,
303305
"\n{}{}{}\n{}{}{}{}{}{}\n",
304306
" Wrong Answer".red().bold(),
@@ -310,9 +312,9 @@ impl std::fmt::Display for VerifyResult {
310312
ca,
311313
"\n Expected: ",
312314
eca,
313-
),
314-
},
315-
},
315+
)
316+
}
317+
}
316318
// Output Timeout Exceeded
317319
13 => write!(
318320
f,

src/cache/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn problem(problems: &mut Vec<Problem>, v: Value) -> Result<(), Error> {
2626
});
2727
}
2828

29-
return Ok(());
29+
Ok(())
3030
}
3131

3232
/// desc parser

src/cache/sql.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub static CREATE_PROBLEMS_IF_NOT_EXISTS: &'static str = r#"
1+
pub static CREATE_PROBLEMS_IF_NOT_EXISTS: &str = r#"
22
CREATE TABLE IF NOT EXISTS problems (
33
category TEXT NOT NULL,
44
fid INTEGER NOT NULL,
@@ -14,7 +14,7 @@ pub static CREATE_PROBLEMS_IF_NOT_EXISTS: &'static str = r#"
1414
)
1515
"#;
1616

17-
pub static CREATE_TAGS_IF_NOT_EXISTS: &'static str = r#"
17+
pub static CREATE_TAGS_IF_NOT_EXISTS: &str = r#"
1818
CREATE TABLE IF NOT EXISTS tags (
1919
tag TEXT NOT NULL,
2020
refs TEXT NOT NULL

src/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
99
use std::{collections::HashMap, fs, path::PathBuf};
1010
use toml;
1111

12-
const DEFAULT_CONFIG: &'static str = r#"
12+
const DEFAULT_CONFIG: &str = r#"
1313
# usually you don't wanna change those
1414
[sys]
1515
categories = [

src/cmds/data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl Command for DataCommand {
6767
let mut title = "\n Cache".digit(63);
6868
title.push_str("Size");
6969
title.push_str("\n ");
70-
title.push_str(&"-".repeat(65).to_string());
70+
title.push_str(&"-".repeat(65));
7171

7272
let mut flags = 0;
7373
if m.is_present("delete") {

src/cmds/list.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ use clap::{App, Arg, ArgMatches, SubCommand};
4545
/// + ...
4646
pub struct ListCommand;
4747

48-
static CATEGORY_HELP: &'static str = r#"Fliter problems by category name
48+
static CATEGORY_HELP: &str = r#"Fliter problems by category name
4949
[alogrithms, database, shell]
5050
"#;
5151

52-
static QUERY_HELP: &'static str = r#"Fliter questions by conditions:
52+
static QUERY_HELP: &str = r#"Fliter questions by conditions:
5353
Uppercase means negative
5454
e = easy E = m+h
5555
m = medium M = e+h
@@ -58,7 +58,7 @@ d = done D = not done
5858
l = locked L = not locked
5959
s = starred S = not starred"#;
6060

61-
static LIST_AFTER_HELP: &'static str = r#"EXAMPLES:
61+
static LIST_AFTER_HELP: &str = r#"EXAMPLES:
6262
leetcode list List all questions
6363
leetcode list array List questions that has "array" in name
6464
leetcode list -c database List questions that in database category
@@ -120,7 +120,7 @@ impl Command for ListCommand {
120120
let cache = Cache::new()?;
121121
let mut ps = cache.clone().get_problems()?;
122122

123-
if ps.len() == 0 {
123+
if ps.is_empty() {
124124
return Self::handler(m);
125125
}
126126

src/cmds/pick.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use clap::{App, Arg, ArgMatches, SubCommand};
3131
/// ```
3232
pub struct PickCommand;
3333

34-
static QUERY_HELP: &'static str = r#"Fliter questions by conditions:
34+
static QUERY_HELP: &str = r#"Fliter questions by conditions:
3535
Uppercase means negative
3636
e = easy E = m+h
3737
m = medium M = e+h
@@ -71,7 +71,7 @@ impl Command for PickCommand {
7171

7272
let cache = Cache::new()?;
7373
let mut problems = cache.get_problems()?;
74-
if problems.len() == 0 {
74+
if problems.is_empty() {
7575
cache.clone().download_problems()?;
7676
Self::handler(m)?
7777
}

src/cmds/stat.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ impl Command for StatCommand {
4444
match i.level {
4545
1 => {
4646
easy += 1.00;
47-
if i.status == "ac".to_string() {
47+
if i.status == "ac" {
4848
easy_ac += 1.00;
4949
}
5050
}
5151
2 => {
5252
medium += 1.00;
53-
if i.status == "ac".to_string() {
53+
if i.status == "ac" {
5454
medium_ac += 1.00;
5555
}
5656
}
5757
3 => {
5858
hard += 1.00;
59-
if i.status == "ac".to_string() {
59+
if i.status == "ac" {
6060
hard_ac += 1.00;
6161
}
6262
}
@@ -114,7 +114,7 @@ impl Command for StatCommand {
114114
print!("{}", done);
115115
println!("{}", udone);
116116
}
117-
println!("");
117+
println!();
118118
Ok(())
119119
}
120120
}

src/helper.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ mod filter {
7070
'M' => ps.retain(|x| x.level != 2),
7171
'h' => ps.retain(|x| x.level == 3),
7272
'H' => ps.retain(|x| x.level != 3),
73-
'd' => ps.retain(|x| x.status == "ac".to_string()),
74-
'D' => ps.retain(|x| x.status != "ac".to_string()),
73+
'd' => ps.retain(|x| x.status == "ac"),
74+
'D' => ps.retain(|x| x.status != "ac"),
7575
_ => {}
7676
}
7777
}
@@ -115,12 +115,11 @@ mod html {
115115
for (i, e) in tks.chars().enumerate() {
116116
match e {
117117
'<' => {
118-
match bold {
119-
true => {
120-
output.push(Token::Bold(tks[ptr..i].to_string()));
121-
bold = false;
122-
}
123-
false => output.push(Token::Plain(tks[ptr..i].to_string())),
118+
if bold {
119+
output.push(Token::Bold(tks[ptr..i].to_string()));
120+
bold = false;
121+
} else {
122+
output.push(Token::Plain(tks[ptr..i].to_string()));
124123
}
125124
ptr = i;
126125
}

0 commit comments

Comments
 (0)