Skip to content

Commit

Permalink
cargo clippy --fix -- -Wclippy::pedantic
Browse files Browse the repository at this point in the history
  • Loading branch information
cantino committed Jul 4, 2024
1 parent f06c5be commit ee9f771
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::env;
pub struct Init {}

impl Init {
#[must_use]
pub fn new(init_mode: &InitMode) -> Self {
match init_mode {
InitMode::Bash => {
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn handle_dump(settings: &Settings) {
fn handle_stats(settings: &Settings) {
let history = History::load(settings.history_format);
let stats = StatsGenerator::new(&history).generate_stats(settings);
println!("{}", stats);
println!("{stats}");
}

fn main() {
Expand Down
15 changes: 6 additions & 9 deletions src/stats_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct StatItem {
impl<'a> StatsGenerator<'a> {
#[must_use]
pub fn generate_stats(&self, settings: &Settings) -> String {
let mut lines = "".to_owned();
let mut lines = String::new();
let count_history = Self::count_commands_from_db_history(self, &None);
if count_history == 0 {
return "No history found in the database".to_string();
Expand All @@ -39,11 +39,8 @@ impl<'a> StatsGenerator<'a> {
);
} else {
lines.push_str(
format!(
" - your history database contains {:?} items\n",
count_history
)
.as_mut_str(),
format!(" - your history database contains {count_history:?} items\n")
.as_mut_str(),
);
}
let most_used_commands = self.most_used_commands(
Expand Down Expand Up @@ -73,7 +70,7 @@ impl<'a> StatsGenerator<'a> {
.push(item);
}

for (dir, items) in directory_map.iter() {
for (dir, items) in &directory_map {
if let Some(dir_name) = dir {
lines.push_str(&format!(
" - top {:?} matching commands in directory {:?}, sorted by occurrence:\n",
Expand Down Expand Up @@ -171,7 +168,7 @@ impl<'a> StatsGenerator<'a> {
query,
&[
(":dir_filter_off", &only_dir.is_none()),
(":only_dir", &only_dir.as_ref().unwrap_or(&"".to_string())),
(":only_dir", &only_dir.as_ref().unwrap_or(&String::new())),
(":min_cmd_length", &min_cmd_length.to_owned()),
(":cmds", &cmds.to_owned()),
(
Expand Down Expand Up @@ -227,7 +224,7 @@ impl<'a> StatsGenerator<'a> {
"SELECT count(1) AS n FROM commands WHERE (:dir_filter_off OR dir = :directory)",
&[
(":dir_filter_off", &dir.is_none()),
(":directory", &dir.as_ref().unwrap_or(&"".to_string())),
(":directory", &dir.as_ref().unwrap_or(&String::new())),
],
|row| Ok(Count { count: row.get(0)? }),
);
Expand Down

0 comments on commit ee9f771

Please sign in to comment.