Skip to content

Commit

Permalink
fixup! Fix #330: Display quick stats πŸ“Š
Browse files Browse the repository at this point in the history
Fix these Clippy warnings:

cargo clippy
    Checking mcfly v0.8.6 (/Users/nicolas/work/mcfly)
warning: useless use of `format!`
  --> src/stats_generator.rs:26:24
   |
26 |         lines.push_str(format!("πŸ“Š Quick stats:\n").as_mut_str());
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"πŸ“Š Quick stats:\n".to_string()`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format
   = note: `#[warn(clippy::useless_format)]` on by default

warning: deref which would be done by auto-deref
  --> src/stats_generator.rs:29:24
   |
29 |           lines.push_str(&*Self::generate_command_stats(
   |  ________________________^
30 | |             self,
31 | |             limit,
32 | |             most_used_commands,
33 | |         ));
   | |_________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref
   = note: `#[warn(clippy::explicit_auto_deref)]` on by default
help: try
   |
29 ~         lines.push_str(&Self::generate_command_stats(
30 +             self,
31 +             limit,
32 +             most_used_commands,
33 ~         ));
   |

warning: accessing first element with `vec.get(0)`
  --> src/stats_generator.rs:82:9
   |
82 |         vec.get(0).unwrap().count
   |         ^^^^^^^^^^ help: try: `vec.first()`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#get_first
   = note: `#[warn(clippy::get_first)]` on by default

warning: `mcfly` (lib) generated 3 warnings (run `cargo clippy --fix --lib
  • Loading branch information
nicokosi committed Jun 4, 2024
1 parent 7878c2a commit c75b41a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/stats_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ impl<'a> StatsGenerator<'a> {
if count_history == 0 {
return "No history, no stats!".to_string();
}
lines.push_str(format!("πŸ“Š Quick stats:\n").as_mut_str());
lines.push_str("πŸ“Š Quick stats:\n");
lines.push_str(format!(" - history has {:?} items ;\n", count_history).as_mut_str());
let most_used_commands = self.most_used_commands(&limit);
lines.push_str(&*Self::generate_command_stats(
lines.push_str(&Self::generate_command_stats(
self,
limit,
most_used_commands,
Expand Down Expand Up @@ -79,7 +79,7 @@ impl<'a> StatsGenerator<'a> {
.run_query("select count(1) as n from commands", &[], |row| {
Ok(Count { count: row.get(0)? })
});
vec.get(0).unwrap().count
vec.first().unwrap().count
}
}

Expand Down

0 comments on commit c75b41a

Please sign in to comment.