Skip to content

Commit 2971132

Browse files
committed
fix: cargo clippy
1 parent 5798505 commit 2971132

File tree

5 files changed

+90
-106
lines changed

5 files changed

+90
-106
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "abhyas"
3-
version = "1.4.0"
3+
version = "1.5.0"
44
edition = "2021"
55
authors = ["Harshal Jadhav <bestt1315@gmail.com>"]
66
homepage = "https://github.com/halshar/abhyas"

src/cli.rs

Lines changed: 68 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ pub fn show_options(db: &Db) -> Result<(), CustomErrors> {
7777
};
7878

7979
match selected_item {
80-
MainMenuOptions::Status => get_status(&db)?,
81-
MainMenuOptions::GetLink => get_link_options(&db)?,
82-
MainMenuOptions::AddLink => add_link_options(&db)?,
83-
MainMenuOptions::DeleteLink => delete_link_options(&db)?,
84-
MainMenuOptions::SearchLink => search_link_options(&db)?,
85-
MainMenuOptions::Other => show_other_options(&db)?,
80+
MainMenuOptions::Status => get_status(db)?,
81+
MainMenuOptions::GetLink => get_link_options(db)?,
82+
MainMenuOptions::AddLink => add_link_options(db)?,
83+
MainMenuOptions::DeleteLink => delete_link_options(db)?,
84+
MainMenuOptions::SearchLink => search_link_options(db)?,
85+
MainMenuOptions::Other => show_other_options(db)?,
8686
MainMenuOptions::Exit => return Err(CustomErrors::Exit),
8787
}
8888

@@ -196,19 +196,16 @@ fn delete_link_options(db: &Db) -> Result<(), CustomErrors> {
196196
_ => unreachable!(),
197197
};
198198

199-
loop {
200-
match selected_option {
201-
DeleteOptions::DeleteLink => {
202-
match db.delete_link(link) {
203-
Ok(_) => show_green("Successfully deleted the link"),
204-
Err(e) => return Err(e),
205-
};
206-
break;
207-
}
208-
DeleteOptions::MainMenu => break,
209-
DeleteOptions::Exit => return Err(CustomErrors::Exit),
210-
};
211-
}
199+
match selected_option {
200+
DeleteOptions::DeleteLink => {
201+
match db.delete_link(link) {
202+
Ok(_) => show_green("Successfully deleted the link"),
203+
Err(e) => return Err(e),
204+
};
205+
}
206+
DeleteOptions::MainMenu => (),
207+
DeleteOptions::Exit => return Err(CustomErrors::Exit),
208+
};
212209

213210
Ok(())
214211
}
@@ -237,26 +234,22 @@ fn single_link_options(db: &Db, link: &str) -> Result<(), CustomErrors> {
237234
_ => unreachable!(),
238235
};
239236

240-
loop {
241-
match selected_option {
242-
GetLinkOptions::MarkAsComplete => {
243-
match db.mark_as_complete(link) {
244-
Ok(_) => show_green("Successfully marked the link as completed"),
245-
Err(e) => return Err(e),
246-
};
247-
break;
248-
}
249-
GetLinkOptions::Skip => {
250-
match db.skip_link(link) {
251-
Ok(_) => show_green("Successfully skipped the link"),
252-
Err(e) => return Err(e),
253-
};
254-
break;
255-
}
256-
GetLinkOptions::MainMenu => break,
257-
GetLinkOptions::Exit => return Err(CustomErrors::Exit),
258-
};
259-
}
237+
match selected_option {
238+
GetLinkOptions::MarkAsComplete => {
239+
match db.mark_as_complete(link) {
240+
Ok(_) => show_green("Successfully marked the link as completed"),
241+
Err(e) => return Err(e),
242+
};
243+
}
244+
GetLinkOptions::Skip => {
245+
match db.skip_link(link) {
246+
Ok(_) => show_green("Successfully skipped the link"),
247+
Err(e) => return Err(e),
248+
};
249+
}
250+
GetLinkOptions::MainMenu => (),
251+
GetLinkOptions::Exit => return Err(CustomErrors::Exit),
252+
};
260253

261254
Ok(())
262255
}
@@ -316,59 +309,46 @@ fn show_other_options(db: &Db) -> Result<(), CustomErrors> {
316309
_ => unreachable!(),
317310
};
318311

319-
loop {
320-
match selected_option {
321-
OtherOptions::ShowAllLinks => match db.get_all_links() {
322-
Ok(val) => {
323-
match val {
324-
Some(all_links) => pretty_print(&all_links),
325-
None => show_red("No Links present in the database :("),
326-
}
327-
break;
328-
}
329-
Err(e) => return Err(e),
312+
match selected_option {
313+
OtherOptions::ShowAllLinks => match db.get_all_links() {
314+
Ok(val) => match val {
315+
Some(all_links) => pretty_print(&all_links),
316+
None => show_red("No Links present in the database :("),
330317
},
331-
OtherOptions::ShowCompletedLinks => match db.get_completed_links() {
332-
Ok(val) => {
333-
match val {
334-
Some(completed_links) => pretty_print(&completed_links),
335-
None => show_red("No Completed Links :("),
336-
}
337-
break;
338-
}
339-
Err(e) => return Err(e),
318+
Err(e) => return Err(e),
319+
},
320+
OtherOptions::ShowCompletedLinks => match db.get_completed_links() {
321+
Ok(val) => match val {
322+
Some(completed_links) => pretty_print(&completed_links),
323+
None => show_red("No Completed Links :("),
340324
},
341-
OtherOptions::ShowSkippedLinks => match db.get_skipped_links() {
342-
Ok(val) => {
343-
match val {
344-
Some(skipped_links) => pretty_print(&skipped_links),
345-
None => show_red("No Skipped Links :)"),
346-
}
347-
break;
348-
}
349-
Err(e) => return Err(e),
325+
Err(e) => return Err(e),
326+
},
327+
OtherOptions::ShowSkippedLinks => match db.get_skipped_links() {
328+
Ok(val) => match val {
329+
Some(skipped_links) => pretty_print(&skipped_links),
330+
None => show_red("No Skipped Links :)"),
350331
},
351-
OtherOptions::SkippedToIncomplete => {
352-
match db.skipped_to_incomplete() {
353-
Ok(count) => show_green(
354-
format!("Changed {} Skipped Links To Incomplete Links", count).as_str(),
355-
),
356-
Err(e) => return Err(e),
357-
};
358-
break;
359-
}
360-
OtherOptions::CompletedToIncomplete => {
361-
match db.completed_to_incomplete() {
362-
Ok(count) => show_green(
363-
format!("Changed {} Completed Links To Incomplete Links", count).as_str(),
364-
),
365-
Err(e) => return Err(e),
366-
};
367-
break;
368-
}
369-
OtherOptions::MainMenu => break,
370-
OtherOptions::Exit => return Err(CustomErrors::Exit),
332+
Err(e) => return Err(e),
333+
},
334+
OtherOptions::SkippedToIncomplete => {
335+
match db.skipped_to_incomplete() {
336+
Ok(count) => show_green(
337+
format!("Changed {} Skipped Links To Incomplete Links", count).as_str(),
338+
),
339+
Err(e) => return Err(e),
340+
};
341+
}
342+
OtherOptions::CompletedToIncomplete => {
343+
match db.completed_to_incomplete() {
344+
Ok(count) => show_green(
345+
format!("Changed {} Completed Links To Incomplete Links", count).as_str(),
346+
),
347+
Err(e) => return Err(e),
348+
};
371349
}
350+
OtherOptions::MainMenu => (),
351+
OtherOptions::Exit => return Err(CustomErrors::Exit),
372352
}
373353

374354
Ok(())

src/database.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,16 @@ impl Db {
5454
&& (err.extended_code == SQLITE_CONSTRAINT_PRIMARYKEY
5555
|| err.extended_code == SQLITE_CONSTRAINT_UNIQUE)
5656
{
57-
return Err(CustomErrors::DuplicateLinkValue);
57+
Err(CustomErrors::DuplicateLinkValue)
5858
} else {
59-
return Err(CustomErrors::Others(
59+
Err(CustomErrors::Others(
6060
"Error: Something went wrong while inserting link".to_owned(),
61-
));
61+
))
6262
}
6363
}
64-
_ => {
65-
return Err(CustomErrors::Others(
66-
"Error: Something went wrong while inserting link".to_owned(),
67-
))
68-
}
64+
_ => Err(CustomErrors::Others(
65+
"Error: Something went wrong while inserting link".to_owned(),
66+
)),
6967
},
7068
}
7169
}

src/utility.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ fn create_file() -> Result<PathBuf, CustomErrors> {
1717
};
1818

1919
let dir_name = &cache_dir.join("abhyas");
20-
match fs::create_dir_all(&dir_name) {
20+
match fs::create_dir_all(dir_name) {
2121
Ok(_) => (),
2222
Err(_) => return Err(CustomErrors::CreateDirectoryFailed),
2323
};
2424

2525
let file_name = &dir_name.join("abhyas.db");
26-
match OpenOptions::new().write(true).create(true).open(&file_name) {
26+
match OpenOptions::new().write(true).create(true).open(file_name) {
2727
Ok(_) => (),
2828
Err(e) => return Err(CustomErrors::FileCreationFailed(e.to_string())),
2929
}
@@ -58,28 +58,34 @@ fn create_db_connection() -> Result<Connection, CustomErrors> {
5858
Ok(conn)
5959
}
6060

61-
pub fn show_green(msg: &str) -> () {
61+
pub fn show_green(msg: &str) {
6262
let mut stdout = StandardStream::stdout(ColorChoice::Always);
6363

64-
if let Err(_) = stdout.set_color(ColorSpec::new().set_fg(Some(Color::Green))) {
64+
if stdout
65+
.set_color(ColorSpec::new().set_fg(Some(Color::Green)))
66+
.is_err()
67+
{
6568
println!("{}", msg);
6669
return;
6770
}
6871

69-
if let Err(_) = writeln!(&mut stdout, "{}", msg) {
72+
if writeln!(&mut stdout, "{}", msg).is_err() {
7073
println!("{}", msg);
7174
}
7275
}
7376

74-
pub fn show_red(msg: &str) -> () {
77+
pub fn show_red(msg: &str) {
7578
let mut stdout = StandardStream::stdout(ColorChoice::Always);
7679

77-
if let Err(_) = stdout.set_color(ColorSpec::new().set_fg(Some(Color::Red))) {
80+
if stdout
81+
.set_color(ColorSpec::new().set_fg(Some(Color::Red)))
82+
.is_err()
83+
{
7884
println!("{}", msg);
7985
return;
8086
}
8187

82-
if let Err(_) = writeln!(&mut stdout, "{}", msg) {
88+
if writeln!(&mut stdout, "{}", msg).is_err() {
8389
println!("{}", msg);
8490
}
8591
}

0 commit comments

Comments
 (0)